docker 列出所有容器id
docker ps -aq
[root@localhost conf]# docker ps -aq f81aa5f48427 06a66409d7ce 1c3d38b948ba 62233dfad35b 4b0032878886 0f6f368c4c1d 7d98a59a8012 1906ba6bfbe1 [root@localhost conf]# [root@localhost conf]# docker ps -aq f81aa5f48427 06a66409d7ce 1c3d38b948ba 62233dfad35b 4b0032878886 0f6f368c4c1d 7d98a59a8012 1906ba6bfbe1 [root@localhost conf]#
docker 查看所有运行容器
docker ps -a
[root@localhost conf]# docker ps -a container id image command created status ports names f81aa5f48427 mysql:8.0.23 "docker-entrypoint.s…" 30 hours ago up 21 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql 06a66409d7ce wurstmeister/kafka "start-kafka.sh" 6 months ago exited (255) 4 months ago 0.0.0.0:9092->9092/tcp kafka 1c3d38b948ba zookeeper "/docker-entrypoint.…" 6 months ago up 2 hours 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp zookeeper 62233dfad35b minio/minio "/usr/bin/docker-ent…" 6 months ago up 2 hours minio-server 4b0032878886 6c3c2a225947 "docker-entrypoint.s…" 6 months ago exited (255) 4 months ago 4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp rabbitmq 0f6f368c4c1d elasticsearch:7.6.2 "/usr/local/bin/dock…" 8 months ago exited (143) 6 months ago elasticsearch 7d98a59a8012 mysql:5.7 "docker-entrypoint.s…" 8 months ago exited (0) 8 months ago mysql-slave 1906ba6bfbe1 mysql:5.7 "docker-entrypoint.s…" 8 months ago exited (137) 8 months ago mysql-master
docker 查看正在运行容器
docker ps
[root@localhost conf]# docker ps container id image command created status ports names f81aa5f48427 mysql:8.0.23 "docker-entrypoint.s…" 30 hours ago up 20 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql 1c3d38b948ba zookeeper "/docker-entrypoint.…" 6 months ago up 2 hours 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp zookeeper 62233dfad35b minio/minio "/usr/bin/docker-ent…" 6 months ago up 2 hours minio-server
docker 停止指定的container(容器)
docker stop containerid
温馨提示:删除container(容器)的镜像文件,必须先停止container(容器)运行。
知识拓展:停止docker 所有容器(包含正在运行)container(容器)
docker stop $(docker ps -a -q) 或者 docker stop $(docker ps -aq)
docker 删除指定的container(容器)
docker rm containerid
知识拓展:想要删除所有container(容器),执行如下指令:
docker rm $(docker ps -a -q) 或者 docker rm $(docker ps -aq)
docker 查看包含images(镜像)
docker images
[root@localhost conf]# docker images repository tag image id created size nginx latest 0e901e68141f 9 months ago 142mb mysql 5.7 2a0961b7de03 9 months ago 462mb minio/minio latest e31e0721a96b 13 months ago 406mb wurstmeister/kafka latest 2dd91ce2efe1 13 months ago 508mb zookeeper latest 36c607e7b14d 14 months ago 278mb rabbitmq management 6c3c2a225947 14 months ago 253mb mysql 8.0.23 cbe8815cbea8 22 months ago 546mb elasticsearch 7.6.2 f29a1ee41030 2 years ago 791mb delron/fastdfs latest 8487e86fc6ee 4 years ago 464mb
docker 删除images(镜像)
docker rmi
docker 删除全部image(镜像)
docker rmi $(docker images -q)
docker 强制删除全部image(镜像)
docker rmi -f $(docker images -q)
docker 停止所有容器
docker container prune
docker 删除所有不使用的镜像
docker image prune --force --all或者docker image prune -f -a
docker 停止、启动、杀死、重启容器
docker stop containername或者containerid docker start containername或者containerid docker kill containername或者containerid docker restart containername或者containerid
docker进入指定容器,查看/修改相关配置文件
docker exec :在运行的容器中执行命令 -d :分离模式: 在后台运行 -i :即使没有附加也保持stdin(标准输入) 打开,以交互模式运行容器,通常与 -t 同时使用; -t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用; docker exec -it mysql /bin/bash
修改配置、退出容器
1、如果要正常退出不关闭容器,请按ctrl p q进行退出容器 2、如果使用exit退出,那么在退出之后会关闭容器,可以使用下面的流程进行恢复 使用docker restart命令重启容器 使用docker attach命令进入容器