Skip to content

Docker 命令备忘录

Docker 容器

查看容器

命令描述
docker ps列出正在运行的容器
docker ps -a列出所有容器
docker logs nginx-server容器日志
docker inspect nginx-server检查容器
docker events nginx-server容器事件
docker port nginx-server公共端口
docker top nginx-server运行进程
docker stats nginx-server容器资源使用
docker diff nginx-server列出对容器所做的更改。

操作容器

命令描述
docker start nginx-server开始
docker stop nginx-server停止
docker restart nginx-server重启
docker pause nginx-server暂停
docker unpause nginx-server取消暂停
docker wait nginx-server阻塞容器
docker kill nginx-server发送 SIGKILL
docker attach nginx-server连接到现有容器
docker rename my-nginx nginx-server重命名容器
docker rm nginx-server删除容器
docker update --cpu-shares 512 -m 300M nginx-server更新容器信息

Docker 镜像

操作镜像

命令描述
docker images列出镜像
docker rmi nginx删除镜像
docker load < ubuntu.tar.gzdocker load --input ubuntu.tar从 tar 文件载入镜像
docker save busybox > ubuntu.tar将镜像另存为 tar 文件
docker history显示镜像的历史
docker commit nginx将容器另存为镜像
docker tag nginx eon01/nginx为镜像打tag
docker push eon01/nginx推送镜像

构建镜像

shell
$ docker build .
$ docker build github.com/creack/docker-firefox
$ docker build - < Dockerfile
$ docker build - < context.tar.gz
$ docker build -t eon/nginx-server .
$ docker build -f myOtherDockerfile .
$ curl example.com/remote/Dockerfile | docker build -f - .

Docker 网络

操作

删除网络

shell
docker network rm MyOverlayNetwork

列出网络

shell
docker network ls

获取有关网络的信息

shell
docker network inspect MyOverlayNetwork

将正在运行的容器连接到网络

shell
docker network connect MyOverlayNetwork nginx

启动时将容器连接到网络

shell
docker run -it -d --network=MyOverlayNetwork nginx

断开容器与网络的连接

shell
docker network disconnect MyOverlayNetwork nginx

创建网络

shell
docker network create -d overlay MyOverlayNetwork
docker network create -d bridge MyBridgeNetwork
docker network create -d overlay \
  --subnet=192.168.0.0/16 \
  --subnet=192.170.0.0/16 \
  --gateway=192.168.0.100 \
  --gateway=192.170.0.100 \
  --ip-range=192.168.1.0/24 \
  --aux-address="my-router=192.168.1.5" \
  --aux-address="my-switch=192.168.1.6" \
  --aux-address="my-printer=192.170.1.5" \
  --aux-address="my-nas=192.170.1.6" \
  MyOverlayNetwork

其他

Docker 仓库

命令描述
docker logindocker login localhost:8080登录 Docker 仓库
docker logoutdocker logout localhost:8080注销登录 Docker 仓库
docker search search_word在 Docker 仓库中搜索镜像
docker pull user/image 从Docker 仓库下载镜像
docker push user/image将镜像上传到Docker 仓库

批量清理

命令描述
docker stop -f $(docker ps -a -q)停止所有容器
docker rm -f $(docker ps -a -q)删除所有容器
docker rmi -f $(docker images -q)删除所有图像

Docker 卷

检查容量

shell
$ docker volume ls

清理未使用的容量

shell
$ docker volume prune

总访问量
总访问人数 人次