[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql 5.7 2a0961b7de03 5 weeks ago 462MB rabbitmq management 1bfc98e879d5 3 months ago 257MB mongo latest 0bcbeb494bed 10 months ago 684MB nginx v3 2c139dd2d638 10 months ago 133MB
-a :列出当前所有正在运行的容器+历史上运行过的 -l :显示最近创建的容器 -n:显示最近n个创建的容器 -q :静默模式,只显示容器编号 --format :指定返回值的模板文件。
e.g.
1 2 3
[root@localhost opt]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5994c6ac58ba nginx:stable-alpine "/docker-entrypoint.…" 21 hours ago Up 21 hours 0.0.0.0:80->80/tcp
# 使用exec,不会导致容器的停止 [root@localhost ~]# docker run --name debian01 -d -it debian dea96e62d3d673f0b5d0cde9cd39a06ec34de1a6c951aa504da9523cfc714c4a [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dea96e62d3d6 debian "bash" 4 seconds ago Up 2 seconds debian01 [root@localhost ~]# docker exec -it debian01 /bin/bash root@dea96e62d3d6:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var root@dea96e62d3d6:/# exit exit [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dea96e62d3d6 debian "bash" 4 seconds ago Up 2 seconds debian01
# 使用attach,会导致容器的停止 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dea96e62d3d6 debian "bash" 4 seconds ago Up 2 seconds debian01 [root@localhost ~]# docker attach debian01 root@dea96e62d3d6:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var root@dea96e62d3d6:/# exit exit [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@localhost ~]# docker run -itd --name nginx -p 80:80 nginx:1.19.3-alpine Unable to find image 'nginx:1.19.3-alpine' locally 1.19.3-alpine: Pulling from library/nginx 188c0c94c7c5: Pull complete 61c2c0635c35: Pull complete 378d0a9d4d5f: Pull complete 2fe865f77305: Pull complete b92535839843: Pull complete Digest: sha256:5aa44b407756b274a600cxxx418bdfb1d02c33317ae27fd5e8a333afb115db1 Status: Downloaded newer image for nginx:1.19.3-alpine docker: Error response from daemon: Conflict. The container name "/nginx" is already in use by container "ff968fb18a4c364f5334930eb192657e09763f4". You have to remove (or rename) that container to be able to reuse that name. See 'docker run --help'. [root@localhost ~]# cd /opt/data && echo "hello nginx" > /opt/data/index.html [root@localhost data]# docker cp /opt/data/index.html nginx:/usr/share/nginx/html/index.html