安装 docker
- 二进制格式
tar -xf /usr/local/src/docker/docker-19.03.9.tgz cd docker/ mv * /usr/bin/ mkdir /etc/docker vi /etc/docker/daemon.json dockerd &
- yum 包
yum install epel-release yum install docker-io
yum install -y yum-utils yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum install docker-ce docker-ce-cli containerd.io systemctl status docker docker -v
默认关闭了【nightly or test】在 docker-ce.repo 中:yum-config-manager --enable docker-ce-nightly yum-config-manager --enable docker-ce-test yum-config-manager --disable docker-ce-nightly yum-config-manager --disable docker-ce-test
指定确定的版本来安装yum list docker-ce --showduplicates | sort -r yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
下载 rpm 包:download[root@docker-01 ~]# ll total 19112 -rw-r--r-- 1 root root 19535688 Jun 24 16:57 docker-ce-17.03.3.ce-1.el7.x86_64.rpm -rw-r--r-- 1 root root 29392 Jun 24 16:57 docker-ce-selinux-17.03.3.ce-1.el7.noarch.rpm [root@docker-01 ~]# yum -y install * [root@docker-01 ~]# systemctl status docker systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: https://docs.docker.com [root@docker-01 ~]# docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 0e03bdcc26d7: Pull complete Digest: sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
-
阿里安装
# step 1: 安装必要的一些系统工具 sudo yum install -y yum-utils device-mapper-persistent-data lvm2 # Step 2: 添加软件源信息 sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # Step 3: 更新并安装Docker-CE sudo yum makecache fast sudo yum -y install docker-ce # Step 4: 开启Docker服务 sudo service docker start # 注意: # 官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,您可以通过以下方式开启。同理可以开启各种测试版本等。 # vim /etc/yum.repos.d/docker-ee.repo # 将[docker-ce-test]下方的enabled=0修改为enabled=1 # # 安装指定版本的Docker-CE: # Step 1: 查找Docker-CE的版本: # yum list docker-ce.x86_64 --showduplicates | sort -r # Loading mirror speeds from cached hostfile # Loaded plugins: branch, fastestmirror, langpacks # docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable # docker-ce.x86_64 17.03.1.ce-1.el7.centos @docker-ce-stable # docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable # Available Packages # Step2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos) # sudo yum -y install docker-ce-[VERSION]
- 服务管理
systemctl start docker systemctl stop docker
- 镜像加速
# 是 daemon.json 不是 docker.json [root@docker-01 ~]# vi /etc/docker/daemon.json { "registry-mirrors": ["http://hub-mirror.c.163.com","https://registry.docker-cn.com","https://mirror.ccs.tencentyun.com"] } # 重启用 restart,reload 不生效 [root@docker-01 ~]# systemctl reload docker [root@docker-01 ~]# docker info [root@docker-01 ~]# systemctl restart docker [root@docker-01 ~]# docker info
# 是 daemon.json 不是 docker.json [root@docker-01 ~]# vi /etc/docker/daemon.json { "registry-mirrors": ["http://hub-mirror.c.163.com","https://registry.docker-cn.com","https://mirror.ccs.tencentyun.com"] } https://docker.mirrors.ustc.edu.cn # 重启用 restart,reload 不生效 [root@docker-01 ~]# systemctl reload docker [root@docker-01 ~]# docker info [root@docker-01 ~]# systemctl restart docker [root@docker-01 ~]# docker info
#这里操作,等同于登录到本地内建虚拟机执行编辑配置的操作 docker-machine ssh default sudo vi /var/lib/boot2docker/profile # --registry-mirror http://hub-mirror.c.163.com exit docker-machine restart default # 检查添加 docker info
- 卸载
卸载 7 的 yumyum remove docker-ce docker-ce-cli containerd.io # $ du -sh /var/lib/docker # 7.2G /var/lib/docker rm -rf /var/lib/docker
镜像操作常用命令
- 检索
docker search 关键字 - 拉取
docker pull 镜像名称[:tag]
tag 表示版本信息,默认是 latest - 本地镜像
docker images - 删除本地镜像
docker rmi IMAGE-ID
容器操作命令
-
# 创建容器 docker run -d [--name 容器名] 镜像名[:tag] #停止容器: docker stop [容器名|CONTAINER-ID] #启动容器: docker start [容器名|CONTAINER-ID] #查看容器 #查看运行中的容器: docker ps #查看所有的现有容器: docker ps -a #删除容器 docker rm [容器名|CONTAINER-ID] #端口映射 docker run -d -p 80:8080 [--name 容器名] [镜像名:tag] #查看容器日志 docker logs [CONTAINER-ID|容器名]
# 启动容器 docker run -d --name myTomcat tomcat:8 # 启动容器并且映射端口到本地监听的 18080(默认tcp) docker run -d -p 18080:8080 --name myTomcat2 tomcat:8
#交互式启动容器 docker run -it --name myCent centos:8 # ctro + p + q 退出容器保持运行,exit 退出并关闭容器
-
# 这是一个正在运行的 tomcat8 $ docker inspect 39692a4836cd [ { "Id": "39692a4836cdb733d4e23e25a0ca8cef1db3680b05c951e50d9489cebf9ed3c4", "Created": "2020-05-11T02:31:15.904851059Z", "Path": "catalina.sh", "Args": [ "run" ], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 3369, "ExitCode": 0, "Error": "", "StartedAt": "2020-05-11T02:31:17.861972617Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "sha256:eb2cfb95e04d8afcdb65c770cd44d9d003836d53fb780e33d3a6f8c5f7d80def", "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/39692a4836cdb733d4e23e25a0ca8cef1db3680b05c951e50d9489cebf9ed3c4/resolv.conf", "HostnamePath": "/mnt/sda1/var/lib/docker/containers/39692a4836cdb733d4e23e25a0ca8cef1db3680b05c951e50d9489cebf9ed3c4/hostname", "HostsPath": "/mnt/sda1/var/lib/docker/containers/39692a4836cdb733d4e23e25a0ca8cef1db3680b05c951e50d9489cebf9ed3c4/hosts", "LogPath": "/mnt/sda1/var/lib/docker/containers/39692a4836cdb733d4e23e25a0ca8cef1db3680b05c951e50d9489cebf9ed3c4/39692a4836cdb733d4e23e25a0ca8cef1db3680b05c951e50d9489cebf9ed3c4-json.log", "Name": "/myTomcat3", "RestartCount": 0, "Driver": "overlay2", "Platform": "linux", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": null, "ContainerIDFile": "", "LogConfig": { "Type": "json-file", "Config": {} }, "NetworkMode": "default", "PortBindings": { "8080/tcp": [ { "HostIp": "127.0.0.1", "HostPort": "28080" } ] }, "RestartPolicy": { "Name": "no", "MaximumRetryCount": 0 }, "AutoRemove": false, "VolumeDriver": "", "VolumesFrom": null, "CapAdd": null, "CapDrop": null, "Capabilities": 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": [ 44, 168 ], "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": "/mnt/sda1/var/lib/docker/overlay2/573c6ae1ee7ed0dddf45564c370c7961965ed39959133e6054b9f51ef5e2d78d-init/diff:/mnt/sda1/var/lib/docker/overlay2/939f7b6cffd167550cbc81d068e60e4a2248031194af3a67ca414eece44260ce/diff:/mnt/sda1/var/lib/docker/overlay2/9e6b65a77e9708516171c5f1195c38d45bea35d4eac7a57202531cc664e94dc6/diff:/mnt/sda1/var/lib/docker/overlay2/c9d0aa7a535d312d95df270d65da969d3650b1ad7dc45bb8c085615164a19c83/diff:/mnt/sda1/var/lib/docker/overlay2/5e8ea3fd89d8b142a2ac440f9fb1866ec6966923057a4d825de3a56a43395a80/diff:/mnt/sda1/var/lib/docker/overlay2/7461dce2b458b7096a62e37c7e57ad3051304e68c573efb57154ff3cc9485efc/diff:/mnt/sda1/var/lib/docker/overlay2/68ee55f7ed04a00750ba39e7ed7c4e3695bfe096efcd10eba1a06a5630ba6b68/diff:/mnt/sda1/var/lib/docker/overlay2/3014a59c9e34aca0f583a5c6c6cfff7326639f55212c96d635d3bc2089724c17/diff:/mnt/sda1/var/lib/docker/overlay2/f1155ae8f0ac20d42c102d09c22b053009458bc6b1d1860dee52040bfecd0ad7/diff:/mnt/sda1/var/lib/docker/overlay2/4e32c8dc9eb7bdaecb59828563e605e65b6819d027ca2623e781db8f06d7ec69/diff:/mnt/sda1/var/lib/docker/overlay2/29b6619ec6af0f8394005bd262084ce8c3786d8cdd80aedccca7b1a5fa224edc/diff", "MergedDir": "/mnt/sda1/var/lib/docker/overlay2/573c6ae1ee7ed0dddf45564c370c7961965ed39959133e6054b9f51ef5e2d78d/merged", "UpperDir": "/mnt/sda1/var/lib/docker/overlay2/573c6ae1ee7ed0dddf45564c370c7961965ed39959133e6054b9f51ef5e2d78d/diff", "WorkDir": "/mnt/sda1/var/lib/docker/overlay2/573c6ae1ee7ed0dddf45564c370c7961965ed39959133e6054b9f51ef5e2d78d/work" }, "Name": "overlay2" }, "Mounts": [], "Config": { "Hostname": "39692a4836cd", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "8080/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/tomcat/bin:/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "LANG=C.UTF-8", "JAVA_HOME=/usr/local/openjdk-8", "JAVA_VERSION=8u252", "JAVA_BASE_URL=https://github.com/AdoptOpenJDK/openjdk8-upstream-binaries/releases/download/jdk8u252-b09/OpenJDK8U-jdk_", "JAVA_URL_VERSION=8u252b09", "CATALINA_HOME=/usr/local/tomcat", "TOMCAT_NATIVE_LIBDIR=/usr/local/tomcat/native-jni-lib", "LD_LIBRARY_PATH=/usr/local/tomcat/native-jni-lib", "GPG_KEYS=05AB33110949707C93A279E3D3EFE6B686867BA6 07E48665A34DCAFAE522E5E6266191C37C037D42 47309207D818FFD8DCD3F83F1931D684307A10A5 541FBE7D8F78B25E055DDEE13C370389288584E7 61B832AC2F1C5A90F0F9B00A1C506407564C17A3 713DA88BE50911535FE716F5208B0AB1D63011C7 79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED 9BA44C2621385CB966EBA586F72C284D731FABEE A27677289986DB50844682F8ACB77FC2E86E29AC A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23", "TOMCAT_MAJOR=8", "TOMCAT_VERSION=8.5.54", "TOMCAT_SHA512=dc3ba0183d1e6f6006e5430e91abbc0758bdb719efebea5809f7034c9a28c590a764d8fcf2528a27a98cb86531e94cd9dc5a92cdbcae36e808ced0e5f1c665b8" ], "Cmd": [ "catalina.sh", "run" ], "Image": "tomcat:8", "Volumes": null, "WorkingDir": "/usr/local/tomcat", "Entrypoint": null, "OnBuild": null, "Labels": {} }, "NetworkSettings": { "Bridge": "", "SandboxID": "6ece37fc03f190194c839f484b5c1a01509f4efaf07594c0e87a58708d80d720", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": { "8080/tcp": [ { "HostIp": "127.0.0.1", "HostPort": "28080" } ] }, "SandboxKey": "/var/run/docker/netns/6ece37fc03f1", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "9cf56b0928db163280fa129a0eb03dd5a857d3bccff09f95328d8fb1c5838ede", "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": "d6a260f49e8de56f2b0cc2b2fad20bd921565525f4e54034d17eed669b596dc4", "EndpointID": "9cf56b0928db163280fa129a0eb03dd5a857d3bccff09f95328d8fb1c5838ede", "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 } } } } ] # 这是一个停止运行的 tomcat9 $ docker inspect 9435318c06ca [ { "Id": "9435318c06cac456ae99efbb78af5ee132512d4e57ef6b64884ed3b247d2eb49", "Created": "2020-05-09T03:05:44.952681404Z", "Path": "catalina.sh", "Args": [ "run" ], "State": { "Status": "exited", "Running": false, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 0, "ExitCode": 130, "Error": "", "StartedAt": "2020-05-09T03:05:47.484205141Z", "FinishedAt": "2020-05-09T03:07:33.953054485Z" }, "Image": "sha256:927899a31456255c1e1a73b97d9a94451c4fcffedab4e0cf18b1c6c4fe4b84ff", "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/9435318c06cac456ae99efbb78af5ee132512d4e57ef6b64884ed3b247d2eb49/resolv.conf", "HostnamePath": "/mnt/sda1/var/lib/docker/containers/9435318c06cac456ae99efbb78af5ee132512d4e57ef6b64884ed3b247d2eb49/hostname", "HostsPath": "/mnt/sda1/var/lib/docker/containers/9435318c06cac456ae99efbb78af5ee132512d4e57ef6b64884ed3b247d2eb49/hosts", "LogPath": "/mnt/sda1/var/lib/docker/containers/9435318c06cac456ae99efbb78af5ee132512d4e57ef6b64884ed3b247d2eb49/9435318c06cac456ae99efbb78af5ee132512d4e57ef6b64884ed3b247d2eb49-json.log", "Name": "/beautiful_brahmagupta", "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, "Capabilities": 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": [ 44, 168 ], "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": "/mnt/sda1/var/lib/docker/overlay2/d1022de2348d9daa174152acab00a8d4b181a9579fbec8c08cbeaeeda023f529-init/diff:/mnt/sda1/var/lib/docker/overlay2/ae1036a63ca9ba4f7f24311b4a98742542a4a0c623db4a36844c269ff0925ca3/diff:/mnt/sda1/var/lib/docker/overlay2/1cb5cd1038068be5f38b9d916b7e8f34349cb4267c25cea1979bebdd2bd5b4fc/diff:/mnt/sda1/var/lib/docker/overlay2/826902e7bb7426b34ae37cc0e5e7ccaec71a635ad6376325f5e6cdade3673b27/diff:/mnt/sda1/var/lib/docker/overlay2/2af0b175306258e8346f19a844e42334120c8fcd5fbb6acd90ea11faab3c4472/diff:/mnt/sda1/var/lib/docker/overlay2/f7b556e3bfdcbe8dfb81e0c87f20d7ccbc6a65aa023887a32158b8758e3213c5/diff:/mnt/sda1/var/lib/docker/overlay2/68ee55f7ed04a00750ba39e7ed7c4e3695bfe096efcd10eba1a06a5630ba6b68/diff:/mnt/sda1/var/lib/docker/overlay2/3014a59c9e34aca0f583a5c6c6cfff7326639f55212c96d635d3bc2089724c17/diff:/mnt/sda1/var/lib/docker/overlay2/f1155ae8f0ac20d42c102d09c22b053009458bc6b1d1860dee52040bfecd0ad7/diff:/mnt/sda1/var/lib/docker/overlay2/4e32c8dc9eb7bdaecb59828563e605e65b6819d027ca2623e781db8f06d7ec69/diff:/mnt/sda1/var/lib/docker/overlay2/29b6619ec6af0f8394005bd262084ce8c3786d8cdd80aedccca7b1a5fa224edc/diff", "MergedDir": "/mnt/sda1/var/lib/docker/overlay2/d1022de2348d9daa174152acab00a8d4b181a9579fbec8c08cbeaeeda023f529/merged", "UpperDir": "/mnt/sda1/var/lib/docker/overlay2/d1022de2348d9daa174152acab00a8d4b181a9579fbec8c08cbeaeeda023f529/diff", "WorkDir": "/mnt/sda1/var/lib/docker/overlay2/d1022de2348d9daa174152acab00a8d4b181a9579fbec8c08cbeaeeda023f529/work" }, "Name": "overlay2" }, "Mounts": [], "Config": { "Hostname": "9435318c06ca", "Domainname": "", "User": "", "AttachStdin": true, "AttachStdout": true, "AttachStderr": true, "ExposedPorts": { "8080/tcp": {} }, "Tty": true, "OpenStdin": true, "StdinOnce": true, "Env": [ "PATH=/usr/local/tomcat/bin:/usr/local/openjdk-11/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "LANG=C.UTF-8", "JAVA_HOME=/usr/local/openjdk-11", "JAVA_VERSION=11.0.7", "JAVA_BASE_URL=https://github.com/AdoptOpenJDK/openjdk11-upstream-binaries/releases/download/jdk-11.0.7%2B10/OpenJDK11U-jdk_", "JAVA_URL_VERSION=11.0.7_10", "CATALINA_HOME=/usr/local/tomcat", "TOMCAT_NATIVE_LIBDIR=/usr/local/tomcat/native-jni-lib", "LD_LIBRARY_PATH=/usr/local/tomcat/native-jni-lib", "GPG_KEYS=05AB33110949707C93A279E3D3EFE6B686867BA6 07E48665A34DCAFAE522E5E6266191C37C037D42 47309207D818FFD8DCD3F83F1931D684307A10A5 541FBE7D8F78B25E055DDEE13C370389288584E7 61B832AC2F1C5A90F0F9B00A1C506407564C17A3 79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED 9BA44C2621385CB966EBA586F72C284D731FABEE A27677289986DB50844682F8ACB77FC2E86E29AC A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23", "TOMCAT_MAJOR=9", "TOMCAT_VERSION=9.0.34", "TOMCAT_SHA512=9cb32f8807c0e8d2457d52ac032bb496ae7921e1ea0a0c8e6082bf8da60bb57c317a3f2376589962123dd803fdd2816ff960339cb851d9859b2241165fbc278e" ], "Cmd": [ "catalina.sh", "run" ], "Image": "tomcat", "Volumes": null, "WorkingDir": "/usr/local/tomcat", "Entrypoint": null, "OnBuild": null, "Labels": {} }, "NetworkSettings": { "Bridge": "", "SandboxID": "7223237e6487cd1bed261dc47e0dfdd0860fbba55c1aea97bdb105f1de9aeb01", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": {}, "SandboxKey": "/var/run/docker/netns/7223237e6487", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "", "Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "MacAddress": "", "Networks": { "bridge": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "cddf9f45df5a57ba7491b78441ebe65bb91c8b1a84c32d9ae1d055b9975eed65", "EndpointID": "", "Gateway": "", "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "", "DriverOpts": null } } } } ]
- 操纵容器
# 指定【容器id】、或者【容器名称】 docker attach myCent docker attach de04fcc86f00
docker exec myCent w docker exec myCent ps -ef docker exec myCent ip ad li # 通过 exec 实现 attach 返回容器的效果 docker exec -t myCent /bin/bash
-
创建新的镜像
docker CONTAINER docker CONTAINER [REPOSITORY[:TAG]] docker commit [-m "Commit message"] [-a "author string"] CONTAINER [REPOSITORY[:TAG]]
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES de04fcc86f00 centos:8 "/bin/bash" 2 hours ago Up About an hour myCent # 从容器开始,创建我自己的【新镜像】 $ docker commit -m "我自己创建的镜像" -a "argor" de04fcc86f00 argor_centos:1 sha256:caa90c434aef5c4503abc6f0627fa6d4ad1456c94f86e6c6b688fa9a08bad556 $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE argor_centos 1 caa90c434aef 7 seconds ago 237MB centos 7 b5b4d78bc90c 5 days ago 203MB centos 8 470671670cac 3 months ago 237MB centos latest 470671670cac 3 months ago 237MB
-
容器数据卷
#默认就是 rw docker run -it -v /data01:/data01 centos # ro docker run -it -v /data02:/data02:ro centos
$ cat mydocker/dockerfile FROM centos VOLUME ["/DATA01","/DATA02","/DATA03"] CMD echo "docker said that welcome argor." CMD /bin/bash $ docker build -f mydocker/dockerfile -t argor/centos:7 . $ docker images argor/centos REPOSITORY TAG IMAGE ID CREATED SIZE argor/centos 7 67716c343a7b 3 minutes ago 203MB $ docker run -it 67716c343a7b /bin/bash [root@b09f60a15446 /]# ls / DATA01 DATA02 DATA03 anaconda-post.log bin dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
- 数据卷容器
docker run -it --name wonderful_swirles argor/demo docker run -it --name again --volumes-from wonderful_swirles argor/demo
docker network
- CURD:创建网络、删除网络、……
#列出网络设备 docker network ls #查看网络设备配置详情 docker network inspect moto #创建网络 docker network create moto 083728225df9e9d966d56bd45241f5bf4220c225857986d9c907a3d0a566bb93 # 删除 指定网络 docker network rm moto # 删除所有自定义网络 docker network prune # 修改网络配置 # 为容器【nginx_moto2】添加一个网络【moto2】 docker network connect moto2 nginx_moto2 # 为容器删除一个网络 bridge docker network disconnect bridge nginx_moto2
Docker .