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(容器),執(zhí)行如下指令:
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 <image id>
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進(jìn)入指定容器,查看/修改相關(guān)配置文件
docker exec :在運行的容器中執(zhí)行命令 -d :分離模式: 在后臺運行 -i :即使沒有附加也保持STDIN(標(biāo)準(zhǔn)輸入) 打開,以交互模式運行容器,通常與 -t 同時使用; -t: 為容器重新分配一個偽輸入終端,通常與 -i 同時使用; docker exec -it mysql /bin/bash
修改配置、退出容器
1、如果要正常退出不關(guān)閉容器,請按Ctrl+P+Q進(jìn)行退出容器 2、如果使用exit退出,那么在退出之后會關(guān)閉容器,可以使用下面的流程進(jìn)行恢復(fù) 使用docker restart命令重啟容器 使用docker attach命令進(jìn)入容器