Docker的容器管理
Posted jks212454
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker的容器管理相关的知识,希望对你有一定的参考价值。
Docker的容器管理
一、容器的创建
1.运行一个挂掉的容器
docker run centos
# 这个写法会产生多条独立的容器记录。且因为容器内没有程序在运行,所以挂了。
[root@node1 ~]# docker run centos
[root@node1 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d01b358d1736 centos "/bin/bash" 4 seconds ago Exited (0) 3 seconds ago gallant_williamson
2db168499262 redis "docker-entrypoint.s…" 24 hours ago Up 24 hours 6379/tcp, 0.0.0.0:8021->8021/tcp, :::8021->8021/tcp cool_ganguly
7bbc90aa1235 nginx "/docker-entrypoint.…" 24 hours ago Created relaxed_brahmagupta
2d9e649a84a2 opensuse "/bin/bash" 24 hours ago Exited (0) 24 hours ago objective_mcnulty
731daf4ecc83 opensuse "bash" 24 hours ago Exited (0) 24 hours ago serene_herschel
5bb956ef369a opensuse "bash" 24 hours ago Exited (0) 24 hours ago vibrant_hopper
fd583c3fba25 fedora "bash" 24 hours ago Exited (0) 24 hours ago practical_tharp
43d6bca30131 centos "bash" 24 hours ago Exited (0) 24 hours ago charming_nightingale
c2e14edd678d ubuntu "bash" 24 hours ago Exited (0) 24 hours ago gracious_robinson
2716e3ec1417 nginx "/docker-entrypoint.…" 25 hours ago Up 25 hours 0.0.0.0:80->80/tcp, :::80->80/tcp naughty_driscoll
273f0fc6a18c nginx "/docker-entrypoint.…" 25 hours ago Created 0.0.0.0:80->80/tcp, :::80->80/tcp relaxed_bassi
68076e397891 nginx "/docker-entrypoint.…" 26 hours ago Created 0.0.0.0:80->80/tcp, :::80->80/tcp crazy_bardeen
964648a939b9 nginx "/docker-entrypoint.…" 26 hours ago Created
2.开启容器运行某个程序
运行容器,且进入容器空间内,运行某个命令
[root@node1 ~]# docker run centos:7.8.2003 ping baidu.com
PING baidu.com (220.181.38.148) 56(84) bytes of data.
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=1 ttl=127 time=31.9 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=127 time=32.2 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=3 ttl=127 time=32.0 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=4 ttl=127 time=31.7 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=5 ttl=127 time=32.6 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=6 ttl=127 time=32.2 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=7 ttl=127 time=32.1 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=8 ttl=127 time=32.2 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=9 ttl=127 time=31.4 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=10 ttl=127 time=31.4 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=11 ttl=127 time=32.1 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=12 ttl=127 time=31.7 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=13 ttl=127 time=32.1 ms
^C
--- baidu.com ping statistics ---
13 packets transmitted, 13 received, 0% packet loss, time 12025ms
rtt min/avg/max/mdev = 31.452/32.021/32.684/0.365 ms
3.运行一个存活的容器
-d 让容器存活运行,针对宿主机而言
--rm 容器挂掉后自动删除
--name 命令容器名称
[root@node1 ~]# docker run -d centos:7.8.2003 ping baidu.com
91abb153df28322c9dcb1dc4a398f21341ca5613c8ecf8b86e996a142e4eaf74
[root@node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91abb153df28 centos:7.8.2003 "ping baidu.com" 5 seconds ago Up 5 seconds suspicious_hoover
2db168499262 redis "docker-entrypoint.s…" 24 hours ago Up 24 hours 6379/tcp, 0.0.0.0:8021->8021/tcp, :::8021->8021/tcp cool_ganguly
2716e3ec1417 nginx "/docker-entrypoint.…" 26 hours ago Up 25 hours 0.0.0.0:80->80/tcp, :::80->80/tcp
4.自定义容器名称
root@node1 ~]# docker run -d --rm --name test-ping centos:7.8.2003 ping baidu.com
cac482a9861efdef656de62b7906d2aa41444c7fc969c44e3f9a2311a6e8b624
[root@node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cac482a9861e centos:7.8.2003 "ping baidu.com" 3 seconds ago Up 3 seconds test-ping
91abb153df28 centos:7.8.2003 "ping baidu.com" 4 minutes ago Up 4 minutes suspicious_hoover
2db168499262 redis "docker-entrypoint.s…" 24 hours ago Up 24 hours 6379/tcp, 0.0.0.0:8021->8021/tcp, :::8021->8021/tcp cool_ganguly
2716e3ec1417 nginx "/docker-entrypoint.…" 26 hours ago Up 26 hours 0.0.0.0:80->80/tcp, :::80->80/tcp naughty_driscoll
[root@node1 ~]# docker stop cac482a9861e
cac482a9861e
[root@node1 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91abb153df28 centos:7.8.2003 "ping baidu.com" 8 minutes ago Up 8 minutes suspicious_hoover
09792427acc4 centos:7.8.2003 "ping baidu.com" 11 minutes ago Exited (0) 11 minutes ago nervous_banzai
aec6f916a630 centos:7.8.2003 "ping baidu.com" 12 minutes ago Exited (0) 11 minutes ago pensive_clarke
6ad4643c4447 centos:7.8.2003 "ping www.baidu.com" 12 minutes ago Exited (2) 12 minutes ago objective_sutherland
dbbdd69a7944 centos:7.8.2003 "bash" 14 minutes ago Exited (0) 14 minutes ago friendly_haslett
d01b358d1736 centos "/bin/bash" 17 minutes ago Exited (0) 17 minutes ago gallant_williamson
2db168499262 redis "docker-entrypoint.s…" 24 hours ago Up 24 hours 6379/tcp, 0.0.0.0:8021->8021/tcp, :::8021->8021/tcp cool_ganguly
7bbc90aa1235 nginx "/docker-entrypoint.…" 24 hours ago Created relaxed_brahmagupta
2d9e649a84a2 opensuse "/bin/bash" 24 hours ago Exited (0) 24 hours ago objective_mcnulty
731daf4ecc83 opensuse "bash" 24 hours ago Exited (0) 24 hours ago serene_herschel
5bb956ef369a opensuse "bash" 24 hours ago Exited (0) 24 hours ago vibrant_hopper
fd583c3fba25 fedora "bash" 24 hours ago Exited (0) 24 hours ago practical_tharp
43d6bca30131 centos "bash" 24 hours ago Exited (0) 24 hours ago charming_nightingale
c2e14edd678d ubuntu "bash" 24 hours ago Exited (0) 24 hours ago gracious_robinson
2716e3ec1417 nginx "/docker-entrypoint.…" 26 hours ago Up 26 hours 0.0.0.0:80->80/tcp, :::80->80/tcp naughty_driscoll
273f0fc6a18c nginx "/docker-entrypoint.…" 26 hours ago Created 0.0.0.0:80->80/tcp, :::80->80/tcp relaxed_bassi
68076e397891 nginx "/docker-entrypoint.…" 26 hours ago Created 0.0.0.0:80->80/tcp, :::80->80/tcp crazy_bardeen
964648a939b9 nginx "/docker-entrypoint.…" 26 hours ago Created
二、查看容器的日志
1.实时监控某个容器日志
[root@node1 ~]# docker logs -f 2716e3ec1417
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2021/07/21 14:24:17 [notice] 1#1: using the "epoll" event method
2021/07/21 14:24:17 [notice] 1#1: nginx/1.21.1
2021/07/21 14:24:17 [notice] 1#1: built by gcc 8.3.0 (Debian 8.3.0-6)
2021/07/21 14:24:17 [notice] 1#1: OS: Linux 4.18.0-80.el8.x86_64
2021/07/21 14:24:17 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2021/07/21 14:24:17 [notice] 1#1: start worker processes
2021/07/21 14:24:17 [notice] 1#1: start worker process 31
2021/07/21 14:27:45 [error] 31#31: *1 open() "/usr/share/nginx/html/24" failed (2: No such file or directory), client: 192.168.200.1, server: localhost, request: "GET /24 HTTP/1.1", host: "192.168.200.135"
192.168.200.1 - - [21/Jul/2021:14:27:45 +0000] "GET /24 HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36" "-"
2021/07/21 14:27:45 [error] 31#31: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.200.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.200.135", referrer: "http://192.168.200.135/24"
192.168.200.1 - - [21/Jul/2021:14:27:45 +0000] "GET /favicon.ico HTTP/1.1" 404 555 "http://192.168.200.135/24" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36" "-"
2021/07/21 14:27:50 [error] 31#31: *1 open() "/usr/share/nginx/html/24" failed (2: No such file or directory), client: 192.168.200.1, server: localhost, request: "GET /24 HTTP/1.1", host: "192.168.200.135"
192.168.200.1 - - [21/Jul/2021:14:27:50 +0000] "GET /24 HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36" "-"
192.168.200.1 - - [21/Jul/2021:14:28:00 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36" "-"
2021/07/21 14:31:04 [notice] 1#1: signal 3 (SIGQUIT) received, shutting down
2021/07/21 14:31:04 [notice] 31#31: gracefully shutting down
2021/07/21 14:31:04 [notice] 31#31: exiting
2021/07/21 14:31:04 [notice] 31#31: exit
2021/07/21 14:31:04 [notice] 1#1: signal 17 (SIGCHLD) received from 31
2021/07/21 14:31:04 [notice] 1#1: worker process 31 exited with code 0
2021/07/21 14:31:04 [notice] 1#1: exit
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: IPv6 listen already enabled
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2021/07/21 14:31:18 [notice] 1#1: using the "epoll" event method
2021/07/21 14:31:18 [notice] 1#1: nginx/1.21.1
2021/07/21 14:31:18 [notice] 1#1: built by gcc 8.3.0 (Debian 8.3.0-6)
2021/07/21 14:31:18 [notice] 1#1: OS: Linux 4.18.0-80.el8.x86_64
2021/07/21 14:31:18 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2021/07/21 14:31:18 [notice] 1#1: start worker processes
2021/07/21 14:31:18 [notice] 1#1: start worker process 24
2.过滤某个容器日志
[root@node1 ~]# docker logs 91abb153df28 |tail -5
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=780 ttl=127 time=30.1 ms
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=781 ttl=127 time=29.8 ms
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=782 ttl=127 time=29.7 ms
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=783 ttl=127 time=29.5 ms
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=784 ttl=127 time=30.1 ms
三、进入正在运行的容器空间
[root@node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91abb153df28 centos:7.8.2003 "ping baidu.com" 16 minutes ago Up 16 minutes suspicious_hoover
2db168499262 redis "docker-entrypoint.s…" 24 hours ago Up 24 hours 6379/tcp, 0.0.0.0:8021->8021/tcp, :::8021->8021/tcp cool_ganguly
2716e3ec1417 nginx "/docker-entrypoint.…" 26 hours ago Up 26 hours 0.0.0.0:80->80/tcp, :::80->80/tcp naughty_driscoll
[root@node1 ~]# docker exec -it 91abb153df28 bash
[root@91abb153df28 /]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 16:00 ? 00:00:00 ping baidu.com
root 7 0 0 16:17 pts/0 00:00:00 bash
root 21 7 0 16:17 pts/0 00:00:00 ps -ef
四、查看容器的信息
[root@node1 ~]# docker container inspect 91abb153df28
[
{
"Id": "91abb153df28322c9dcb1dc4a398f21341ca5613c8ecf8b86e996a142e4eaf74",
"Created": "2021-07-22T16:00:25.2705954Z",
"Path": "ping",
"Args": [
"baidu.com"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 14927,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-07-22T16:00:25.481107024Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:afb6fca791e071c66276202f8efca5ce3d3dc4fb218bcddff1bc565d981ddd1e",
"ResolvConfPath": "/var/lib/docker/containers/91abb153df28322c9dcb1dc4a398f21341ca5613c8ecf8b86e996a142e4eaf74/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/91abb153df28322c9dcb1dc4a398f21341ca5613c8ecf8b86e996a142e4eaf74/hostname",
"HostsPath": "/var/lib/docker/containers/91abb153df28322c9dcb1dc4a398f21341ca5613c8ecf8b86e996a142e4eaf74/hosts",
"LogPath": "/var/lib/docker/containers/91abb153df28322c9dcb1dc4a398f21341ca5613c8ecf8b86e996a142e4eaf74/91abb153df28322c9dcb1dc4a398f21341ca5613c8ecf8b86e996a142e4eaf74-json.log",
"Name": "/suspicious_hoover",
"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,
"CgroupnsMode": "host",
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"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": 0,
"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,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"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/461b6d0fd0a94cb0ca5fdbbfc1bfb6371e58d05fbc3d9d5d868e33efb86f61bc-init/diff:/var/lib/docker/overlay2/c4fc8645dba560891da2786efe974432eb221f63cc8986ecccb4a28a77176ce9/diff",
"MergedDir": "/var/lib/docker/overlay2/461b6d0fd0a94cb0ca5fdbbfc1bfb6371e58d05fbc3d9d5d868e33efb86f61bc/merged",
"UpperDir": "/var/lib/docker/overlay2/461b6d0fd0a94cb0ca5fdbbfc1bfb6371e58d05fbc3d9d5d868e33efb86f61bc/diff",
"WorkDir": "/var/lib/docker/overlay2/461b6d0fd0a94cb0ca5fdbbfc1bfb6371e58d05fbc3d9d5d868e33efb86f61bc/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "91abb153df28",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"ping",
"baidu.com"
],
"Image": "centos:7.8.2003",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "20200504",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS",
"org.opencontainers.image.created": "2020-05-04 00:00:00+01:00",
"org.opencontainers.image.licenses": "GPL-2.0-only",
"org.opencontainers.image.title": "CentOS Base Image",
"org.opencontainers.image.vendor": "CentOS"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "a492cb90bf8e5100a4bf5228dfdab14efa0fa27fc3ed4cb92d0083bfba7ca3bd",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/a492cb90bf8e",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "9f57ed117bd308a40adc6e0c8563309c0559adc2ab69d81e28af563ab53ce4dd",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.4",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:04",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "9d69c7098d163d0e7e02b1e6da0feed684de33bd6b5a6f16d75900d74fa3f91c",
"EndpointID": "9f57ed117bd308a40adc6e0c8563309c0559adc2ab69d81e28af563ab53ce4dd",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.4",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:04",
"DriverOpts": null
}
}
}
}
]
五、容器的端口映射
1.进入容器内查看服务文件
[root@node1 ~]# docker run -it nginx sh
# cat /etc/red ^H^H^H^C
# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
# pwd
/
# ls
bin boot dev docker-entrypoint.d docker-entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
# cat docker-entrypoint.sh
#!/bin/sh
# vim:sw=4:ts=4:et
set -e
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
exec 3>&1
else
exec 3>/dev/null
fi
if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
echo >&3 "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
case "$f" in
*.sh)
if [ -x "$f" ]; then
echo >&3 "$0: Launching $f";
"$f"
else
# warn on shell scripts without exec bit
echo >&3 "$0: Ignoring $f, not executable";
fi
;;
*) echo >&3 "$0: Ignoring $f";;
esac
done
echo >&3 "$0: Configuration complete; ready for start up"
else
echo >&3 "$0: No files found in /docker-entrypoint.d/, skipping configuration"
fi
fi
exec "$@"
2.进行容器端口映射
后台运行nginx容器,并且命名容器空间,且端口映射宿主
以上是关于Docker的容器管理的主要内容,如果未能解决你的问题,请参考以下文章