Docker 常用命令
更新: 2024-06-03 15:07:40 字数: 0 字 时长: 0 分钟
查看、启动、停止、重启容器
sh
docker ps -a
docker start 容器
docker stop 容器
docker restart 容器查看指定容器最新 N 条日志
sh
docker logs --tail 100 容器查看网络
sh
docker network ls查看网络数据源
sh
docker network inspect 网络名将正在运行的容器连接到网络
sh
docker network connect 网络名 正在运行的容器强制断开容器的网络连接
sh
docker network disconnect 网络名 容器启动时将容器连接到网络
sh
docker run -itd --net=网络名 即将启动的容器指定容器的 IP 地址
sh
docker network connect --ip 172.17.0.1 网络名 容器创建网络
sh
docker network create --subnet=172.18.0.0/16 --gateway=172.18.0.16 网络名删除网络
sh
docker network rm 网络名删除所有无用的网络
sh
docker network prune删除指定容器
sh
docker rm -f 容器删除未启动成功的容器
sh
docker rm $(docker ps -qf status=created)删除退出状态的容器
sh
docker rm $(docker ps -qf status=exited)删除所有未运行的容器
sh
docker rm $(docker ps -a -q)停用全部运行中的容器
sh
docker stop $(docker ps -q) & docker rm $(docker ps -a -q)停用并删除全部运行中的容器
sh
docker stop $(docker ps -q) & docker rm $(docker ps -a -q)查看系统本地所有的镜像
sh
docker images查找镜像
sh
docker search 镜像拉取镜像
sh
docker pull 镜像删除指定镜像
sh
docker rmi -f 镜像删除所有镜像
sh
docker rmi -f $(docker images -aq)查看容器的磁盘使用情况
sh
docker system df查看单个镜像、容器大小
sh
docker system df -v清理磁盘,删除关闭的容器、无用的数据卷和网络,以及 dangling 镜像(即无 tag 的镜像)
sh
docker system prune将没有容器使用 Docker 镜像都删掉,清理得更加彻底
sh
docker system prune -a




