Commands: attach Attach 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.
[root@node1 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2886e49b8809 centos:latest "tailf /var/log/last…" About a minute ago Up About a minute test
查看所有容器
1 2 3 4
[root@node1 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8667cfc10391 centos:latest "tailf /var/log/mess" 4 seconds ago Exited (1) 3 seconds ago sleepy_poincare 2886e49b8809 centos:latest "tailf /var/log/last…" 2 minutes ago Up 2 minutes test
所有容器包含所有状态的容器,包括创建、运行、停止等。
查看容器日志
1
[root@node1 ~]# docker logs test
3. 停止容器
1 2 3 4 5 6
[root@node1 ~]# docker stop test test [root@node1 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8667cfc10391 centos:latest "tailf /var/log/mess" 2 minutes ago Exited (1) 2 minutes ago sleepy_poincare 2886e49b8809 centos:latest "tailf /var/log/last…" 4 minutes ago Exited (137) 32 seconds ago test
后面接容器名或容器ID都可以
4. 启动/重启容器
启动
1 2 3 4 5
[root@node1 ~]# docker start test test [root@node1 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2886e49b8809 centos:latest "tailf /var/log/last…" 5 minutes ago Up 3 seconds test
重启
1 2 3 4 5
[root@node1 ~]# docker restart test test [root@node1 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2886e49b8809 centos:latest "tailf /var/log/last…" 6 minutes ago Up 5 seconds test
5. 删除容器
docker默认只能删除停止状态的容器
1 2 3 4 5 6 7 8
[root@node1 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8667cfc10391 centos:latest "tailf /var/log/mess" 6 minutes ago Exited (1) 6 minutes ago sleepy_poincare 2886e49b8809 centos:latest "tailf /var/log/last…" 8 minutes ago Up 2 minutes test [root@node1 ~]# docker rm sleepy_poincare sleepy_poincare [root@node1 ~]# docker rm test Error response from daemon: You cannot remove a running container 2886e49b88098325c98c7e2edf28aa6bf767795fd1a2dd411f5f0aa9d7333983. Stop the container before attempting removal or force remove
可以先停止容器,再删除。
如果需要强制删除运行中的容器,直接加参数’-f’或’–force’即可
1 2 3 4
[root@node1 ~]# docker rm -f test test [root@centos-vm7 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES