docker容器管理

Posted yinshoucheng-golden

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker容器管理相关的知识,希望对你有一定的参考价值。

创建容器常用选项
[[email protected] ~]# docker container help

Usage: docker container COMMAND

Manage containers

Commands:
attach Attach local standard input, output, and error streams to a running container
commit Create a new image from a container‘s changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container‘s filesystem
exec Run a command in a running container
export Export a container‘s filesystem as a tar archive
inspect Display detailed information on one or more containers
kill Kill one or more running containers
logs Fetch the logs of a container
ls List containers
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
prune Remove all stopped containers
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
run Run a command in a new container
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
wait Block until one or more containers stop, then print their exit codes

Run ‘docker container COMMAND --help‘ for more information on a command.
-i,--ineractive:交互式
-t,--tty:分配一个伪终端
-d,--detach:运行容器到后台
-a,--attach list:附加到运行的容器
--dns list:设置DNS服务器
-e,--env list:设置环境变量
--env-file list:从文件读取环境变量
-p,--publish list:发布容器端口到主机
-P,--publish-all:发布容器所有expose的端口到宿主机随机端口
-h,--hostname string:设置容器主机名
--ip strting:指定容器ip,只能用于自定义网络
--link list:添加连接到另一个容器
--network:连接容器到一个网络
--mount mount:挂载宿主机分区到容器
-v,--volume list:挂载宿主机目录到容器
--restart string:容器退出时重启策略,默认no,[always|on-failure]
--add-host list:添加其他主机到容器中/etc/hosts
-m,--memory:容器可以使用的最大内存量
--memory-swap:允许交换到磁盘的内存量
--memory-swappiness=<0-100>:容器使用swap分区交换的百分比(0-100,默认为-1)
--memory-reservation:内存软限制,docker检测主机容器争用或内存不足时所激活的软限制,使用此选项,值必须设置低于--memory,以使其优先
--oom-kill-disable:当宿主机内存不足时,内核会杀死容器中的进程。建议设置了--memory选项再禁用OOM。如果没有设置,主机可能会耗尽内存。
--cpus:限制容器可以使用多少可用的cpu资源
--cpuset-cpus:限制容器可以使用特定的cpu
--cpu-shares:此值设置为大于或小于默认1024值,以增加或减少容器的权重,并使其可以访问主机cpu周期的更大或更小比例。
后台启动busybox命名为bs
[[email protected] ~]# docker container run -itd --name bs busybox
fa69fa8d97c1481c485771540235fc41d4b3edeb8c0417247a44612df276e44c
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fa69fa8d97c1 busybox "sh" 15 seconds ago Up 13 seconds bs
进入bs容器
[[email protected] ~]# docker container attach bs
/ # ls
bin dev etc home proc root sys tmp usr var
/ # ps -ef
PID USER TIME COMMAND
1 root 0:00 sh
7 root 0:00 ps -ef
/ # ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:02
inet addr:172.17.0.2 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1296 (1.2 KiB) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
退出容器不终止容器运行
ctrl+p+q
[[email protected] ~]# docker container attach bs
/ # mount
rootfs on / type rootfs (rw)
overlay on / type overlay (rw,seclabel,relatime,lowerdir=/var/lib/docker/overlay2/l/ZX36XJX24YFOZ5XKESXWHVFDO2:/var/lib/docker/overlay2/l/RRV6Q6UZEALR2NKQTXJT6G6ESW,upperdir=/var/lib/docker/overlay2/834fa93cd6220fca1a5b07d13d8730a2b7ee5031e716fa0f83d42500cec20040/diff,workdir=/var/lib/docker/overlay2/834fa93cd6220fca1a5b07d13d8730a2b7ee5031e716fa0f83d42500cec20040/work)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev type tmpfs (rw,seclabel,nosuid,size=65536k,mode=755)
devpts on /dev/pts type devpts (rw,seclabel,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)
sysfs on /sys type sysfs (ro,seclabel,nosuid,nodev,noexec,relatime)
tmpfs on /sys/fs/cgroup type tmpfs (ro,seclabel,nosuid,nodev,noexec,relatime,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (ro,seclabel,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (ro,seclabel,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/cpuset type cgroup (ro,seclabel,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/freezer type cgroup (ro,seclabel,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/memory type cgroup (ro,seclabel,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/pids type cgroup (ro,seclabel,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (ro,seclabel,nosuid,nodev,noexec,relatime,net_prio,net_cls)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (ro,seclabel,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/blkio type cgroup (ro,seclabel,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/devices type cgroup (ro,seclabel,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/perf_event type cgroup (ro,seclabel,nosuid,nodev,noexec,relatime,perf_event)
mqueue on /dev/mqueue type mqueue (rw,seclabel,nosuid,nodev,noexec,relatime)
/dev/mapper/centos-root on /etc/resolv.conf type xfs (rw,seclabel,relatime,attr2,inode64,noquota)
/dev/mapper/centos-root on /etc/hostname type xfs (rw,seclabel,relatime,attr2,inode64,noquota)
/dev/mapper/centos-root on /etc/hosts type xfs (rw,seclabel,relatime,attr2,inode64,noquota)
shm on /dev/shm type tmpfs (rw,seclabel,nosuid,nodev,noexec,relatime,size=65536k)
devpts on /dev/console type devpts (rw,seclabel,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)
proc on /proc/bus type proc (ro,relatime)
proc on /proc/fs type proc (ro,relatime)
proc on /proc/irq type proc (ro,relatime)
proc on /proc/sys type proc (ro,relatime)
proc on /proc/sysrq-trigger type proc (ro,relatime)
tmpfs on /proc/asound type tmpfs (ro,seclabel,relatime)
tmpfs on /proc/acpi type tmpfs (ro,seclabel,relatime)
tmpfs on /proc/kcore type tmpfs (rw,seclabel,nosuid,size=65536k,mode=755)
tmpfs on /proc/keys type tmpfs (rw,seclabel,nosuid,size=65536k,mode=755)
tmpfs on /proc/timer_list type tmpfs (rw,seclabel,nosuid,size=65536k,mode=755)
tmpfs on /proc/timer_stats type tmpfs (rw,seclabel,nosuid,size=65536k,mode=755)
tmpfs on /proc/sched_debug type tmpfs (rw,seclabel,nosuid,size=65536k,mode=755)
tmpfs on /proc/scsi type tmpfs (ro,seclabel,relatime)
tmpfs on /sys/firmware type tmpfs (ro,seclabel,relatime)
容器启动时会自动加载宿主机的/etc/resolv.conf、/etc/hostname、/etc/hosts,在容器内修改这三个文件后,重启容器将会失效。
创建容器时指定变量
[[email protected] ~]# docker container run -itd -e a=test --name bs2 busybox
6e81c09be096def517810035beab06e673a6cf1b00a39a6a504e3c64c29b760a
使用exec进入容器退出时不会终止容器运行
[[email protected] ~]# docker exec -i bs2 sh
echo $a
test
容器启动时指定宿主机端口与容器内端口绑定
[[email protected] ~]# docker container run -itd -p 8080:80 --name nginx02 nginx
0549890f9a20fdbf88085f9a7ffc0a8979141fbf84e05b2b75c181d3da1b8e5c
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0549890f9a20 nginx "nginx -g ‘daemon of…" 9 seconds ago Up 6 seconds 0.0.0.0:8080->80/tcp nginx02
6e81c09be096 busybox "sh" 4 minutes ago Up 4 minutes bs2
技术图片

查看容器日志
[[email protected] ~]# docker logs nginx02
192.168.193.1 - - [08/Jun/2019:02:16:37 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/72.0.3626.121 Safari/537.36" "-"
2019/06/08 02:16:38 [error] 6#6: 1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.193.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.193.128:8080", referrer: "http://192.168.193.128:8080/"
192.168.193.1 - - [08/Jun/2019:02:16:38 +0000] "GET /favicon.ico HTTP/1.1" 404 555 "http://192.168.193.128:8080/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36" "-"
192.168.193.1 - - [08/Jun/2019:02:17:12 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" "-"
2019/06/08 02:17:13 [error] 6#6:
4 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.193.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.193.128:8080"
192.168.193.1 - - [08/Jun/2019:02:17:13 +0000] "GET /favicon.ico HTTP/1.1" 404 153 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; Trident/7.0; rv:11.0) like Gecko" "-"
日志文件存储位置
[[email protected] ~]# cd /var/lib/docker/containers/0549890f9a20fdbf88085f9a7ffc0a8979141fbf84e05b2b75c181d3da1b8e5c/
[[email protected] 0549890f9a20fdbf88085f9a7ffc0a8979141fbf84e05b2b75c181d3da1b8e5c]# tail 0549890f9a20fdbf88085f9a7ffc0a8979141fbf84e05b2b75c181d3da1b8e5c-json.log
"log":"192.168.193.1 - - [08/Jun/2019:02:16:37 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36" "-"\\r\\n","stream":"stdout","time":"2019-06-08T02:16:38.031072525Z"
"log":"2019/06/08 02:16:38 [error] 6#6: 1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.193.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.193.128:8080", referrer: "http://192.168.193.128:8080/"\\r\\n","stream":"stdout","time":"2019-06-08T02:16:38.809727552Z"
"log":"192.168.193.1 - - [08/Jun/2019:02:16:38 +0000] "GET /favicon.ico HTTP/1.1" 404 555 "http://192.168.193.128:8080/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36" "-"\\r\\n","stream":"stdout","time":"2019-06-08T02:16:38.809798608Z"
"log":"192.168.193.1 - - [08/Jun/2019:02:17:12 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" "-"\\r\\n","stream":"stdout","time":"2019-06-08T02:17:12.795881354Z"
"log":"2019/06/08 02:17:13 [error] 6#6:
4 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.193.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.193.128:8080"\\r\\n","stream":"stdout","time":"2019-06-08T02:17:13.354414883Z"
"log":"192.168.193.1 - - [08/Jun/2019:02:17:13 +0000] "GET /favicon.ico HTTP/1.1" 404 153 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; Trident/7.0; rv:11.0) like Gecko" "-"\\r\\n","stream":"stdout","time":"2019-06-08T02:17:13.356136349Z"、
容器启动时指定重启策略
[[email protected] ~]# docker container run -itd -p 8081:80 --name nginx03 --restart=always nginx
fd7e0137d4a040a979d7fd3aa04a0699561f1b0bd9fb5506bbda6bc468c8b230
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fd7e0137d4a0 nginx "nginx -g ‘daemon of…" 5 seconds ago Up 3 seconds 0.0.0.0:8081->80/tcp nginx03
0549890f9a20 nginx "nginx -g ‘daemon of…" 13 minutes ago Up 13 minutes 0.0.0.0:8080->80/tcp nginx02
6e81c09be096 busybox "sh" 17 minutes ago Up 17 minutes bs2
容器启动时设置可使用的memory最大值
[[email protected] ~]# docker container run -itd --memory 512m --name nginx04 nginx
2d2b98dcbdd1583039e84b222fc6e8edcabb74cb4cb721bd57aa183aaa7ef7f2
查看指定容器资源使用情况
[[email protected] ~]# docker container stats nginx04
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
2d2b98dcbdd1 nginx04 0.00% 1.352MiB / 512MiB 0.26% 648B / 0B 0B / 0B 2
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
2d2b98dcbdd1 nginx04 0.00% 1.352MiB / 512MiB 0.26% 648B / 0B
管理容器常用命令
ls:列出容器
inspect:显示一个或多个容器详细信息
attach:附加本地标准输入、输出和错误到一个运行的容器
exec:在运行容器中执行命令
commit:创建一个新镜像来自一个容器
cp:拷贝文件/文件夹到一个容器
logs:获取一个容器日志
port:列出或指定容器端口映射
stats:显示容器资源使用统计
top:显示一个容器运行的进程
update:更新一个或多个容器配置
stop/start:停止/启动一个或多个容器
rm:删除一个或多个容器
查看运行的容器
[[email protected] ~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2d2b98dcbdd1 nginx "nginx -g ‘daemon of…" 10 minutes ago Up 10 minutes 80/tcp nginx04
fd7e0137d4a0 nginx "nginx -g ‘daemon of…" 19 minutes ago Up 19 minutes 0.0.0.0:8081->80/tcp nginx03
0549890f9a20 nginx "nginx -g ‘daemon of…" 33 minutes ago Up 33 minutes 0.0.0.0:8080->80/tcp nginx02
6e81c09be096 busybox "sh" 37 minutes ago Up 37 minutes bs2
查看容器详细信息
[[email protected] ~]# docker container inspect 2d2b98dcbdd1
[

"Id": "2d2b98dcbdd1583039e84b222fc6e8edcabb74cb4cb721bd57aa183aaa7ef7f2",
"Created": "2019-06-08T02:38:05.721362153Z",
"Path": "nginx",
"Args": [
"-g",
"daemon off;"
],
"State":
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 4560,
"ExitCode": 0,
"Error": "",
"StartedAt": "2019-06-08T02:38:06.745451785Z",
"FinishedAt": "0001-01-01T00:00:00Z"
,
"Image": "sha256:62c261073ecffe22a28f2ba67760a9320bc4bfe8136a83ba9b579983346564be",
"ResolvConfPath": "/var/lib/docker/containers/2d2b98dcbdd1583039e84b222fc6e8edcabb74cb4cb721bd57aa183aaa7ef7f2/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/2d2b98dcbdd1583039e84b222fc6e8edcabb74cb4cb721bd57aa183aaa7ef7f2/hostname",
"HostsPath": "/var/lib/docker/containers/2d2b98dcbdd1583039e84b222fc6e8edcabb74cb4cb721bd57aa183aaa7ef7f2/hosts",
"LogPath": "/var/lib/docker/containers/2d2b98dcbdd1583039e84b222fc6e8edcabb74cb4cb721bd57aa183aaa7ef7f2/2d2b98dcbdd1583039e84b222fc6e8edcabb74cb4cb721bd57aa183aaa7ef7f2-json.log",
"Name": "/nginx04",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig":
"Binds": null,
"ContainerIDFile": "",
"LogConfig":
"Type": "json-file",
"Config":
,
"NetworkMode": "default",
"PortBindings": ,
"RestartPolicy":
"Name": "no",
"MaximumRetryCount": 0
,
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 536870912,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 1073741824,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
,
"GraphDriver":
"Data":
"LowerDir": "/var/lib/docker/overlay2/eda22799274a018d3d8ee2b1e2e558b07dda1bf76baf3a5207bef73ea08f0e81-init/diff:/var/lib/docker/overlay2/c5e5d61d04d7659136d27a78a17b2bdc66f6a01d48d33da7872d0ad056387961/diff:/var/lib/docker/overlay2/cc87902e3a53ec2d035789fd293dd20d3f2c5483c36ded801dde84567abf8b9e/diff:/var/lib/docker/overlay2/a5fe97da169a47defdb199e3b1ef5ef50702864f57998b2b4958e38ca4150ccc/diff",
"MergedDir": "/var/lib/docker/overlay2/eda22799274a018d3d8ee2b1e2e558b07dda1bf76baf3a5207bef73ea08f0e81/merged",
"UpperDir": "/var/lib/docker/overlay2/eda22799274a018d3d8ee2b1e2e558b07dda1bf76baf3a5207bef73ea08f0e81/diff",
"WorkDir": "/var/lib/docker/overlay2/eda22799274a018d3d8ee2b1e2e558b07dda1bf76baf3a5207bef73ea08f0e81/work"
,
"Name": "overlay2"
,
"Mounts": [],
"Config":
"Hostname": "2d2b98dcbdd1",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts":
"80/tcp":
,
"Tty": true,
"OpenStdin": true,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.17.0",
"NJS_VERSION=0.3.2",
"PKG_RELEASE=1~stretch"
],
"Cmd": [
"nginx",
"-g",
"daemon off;"
],
"ArgsEscaped": true,
"Image": "nginx",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels":
"maintainer": "NGINX Docker Maintainers [email protected]"
,
"StopSignal": "SIGTERM"
,
"NetworkSettings":
"Bridge": "",
"SandboxID": "2dc14468d863863e1e93ddd56040b73b13985b8585ab659649a65b5111d198c0",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports":
"80/tcp": null
,
"SandboxKey": "/var/run/docker/netns/2dc14468d863",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "3311074541d8c17d45adabb2dc333720a17b2ea39918d4bf53b2887825e253e7",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.5",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:05",
"Networks":
"bridge":
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "88dd4fd8b152fc1dcacc1944bcfc6acebc606a04d7300de32fc406e772475bbd",
"EndpointID": "3311074541d8c17d45adabb2dc333720a17b2ea39918d4bf53b2887825e253e7",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.5",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:05",
"DriverOpts": null



]
[[email protected] ~]# docker container top nginx03
UID PID PPID C STIME TTY TIME CMD
root 4449 4431 0 10:29 pts/0 00:00:00 nginx: master process nginx -g daemon off;
101 4484 4449 0 10:29 pts/0 00:00:00 nginx: worker process
进入容器内,容器是基于最精简的linux操作系统,很多指令并未安装,可以自行安装
[[email protected] ~]# docker exec -it nginx03 bash
[email protected]:
[[email protected] ~]# docker exec -it nginx03 sh
[email protected]:
从宿主机复制文件到容器内(不建议使用,推荐在dockerfile中指定)
[[email protected] ~]# docker container exec nginx03 ls /root
[[email protected] ~]# docker container cp anaconda-ks.cfg nginx03:/root
[[email protected] ~]# docker container exec nginx03 ls /root
anaconda-ks.cfg
查看端口映射
[[email protected] ~]# docker port nginx03
80/tcp -> 0.0.0.0:8081

以上是关于docker容器管理的主要内容,如果未能解决你的问题,请参考以下文章

【docker】docker的容器创建与管理过程

Docker容器管理

Docker容器的网络管理和网络隔离

Docker部署Rstudio Server【三】:docker容器管理初步

Docker容器管理总结

Docker容器日志管理介绍