docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 014732a965e9 nginx "/docker-entrypoint.…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp, :::80->80/tcp wonderful_snyder
zhi@thinkpad:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 014732a965e9 nginx "/docker-entrypoint.…" 10 minutes ago Up 10 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp wonderful_snyder zhi@thinkpad:~$ docker stop 014732a965e9 014732a965e9 zhi@thinkpad:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES zhi@thinkpad:~$
此时已经无法访问192.168.10.115:80 重新启动
1
docker start 014732a965e9
执行之后又可以正常访问80端口了,这样就实现了快速启停。
Docker的生命周期
Docker的镜像原理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
zhi@thinkpad:~$ docker pull redis Using default tag: latest latest: Pulling from library/redis 31b3f1ad4ce1: Already exists ff29a33e56fb: Pull complete b230e0fd0bf5: Pull complete 7fe3ad196642: Pull complete 3d8096d6920c: Pull complete 85e4b89053d8: Pull complete Digest: sha256:091a7b5de688f283b30a4942280b64cf822bbdab0abfb2d2ce6db989f2d3c3f4 Status: Downloaded newer image for redis:latest docker.io/library/redis:latest zhi@thinkpad:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE redis latest 2460522297a1 5 days ago 117MB nginx latest 2d389e545974 5 days ago 142MB slepp/arduino latest 5e10cf71a843 4 years ago 893MB
zhi@thinkpad:~$ docker pull centos:7.8.2003 7.8.2003: Pulling from library/centos 9b4ebb48de8d: Pull complete Digest: sha256:8540a199ad51c6b7b51492fa9fee27549fd11b3bb913e888ab2ccf77cbb72cc1 Status: Downloaded newer image for centos:7.8.2003 docker.io/library/centos:7.8.2003 zhi@thinkpad:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE redis latest 2460522297a1 5 days ago 117MB nginx latest 2d389e545974 5 days ago 142MB centos 7.8.2003 afb6fca791e0 2 years ago 203MB slepp/arduino latest 5e10cf71a843 4 years ago 893MB #运行容器且进入容器内 -i 交互式命令操作。我执行ls命令后可以立即返回一个结果 -t 开启一个终端 bash 进入容器后,执行的命令。ls等的命令都是通过bash来执行的 zhi@thinkpad:~$ docker run -it afb6fca791e0 bash [root@603a1d5e03d1 /]# ls anaconda-post.log dev home lib64 mnt proc run srv tmp var bin etc lib media opt root sbin sys usr [root@603a1d5e03d1 /]# cat /etc/redhat-release CentOS Linux release 7.8.2003 (Core) [root@603a1d5e03d1 /]# uname -r 5.15.0-46-generic [root@603a1d5e03d1 /]# exit exitdo