Docker常用命令汇总(自己总结)

删除所有镜像

docker rmi $(docker images -q)

清除坏的:镜像

docker rmi $(docker images -f "dangling=true" -q)

删除docker images中为none的镜像

docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker stop
docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker rm
docker images|grep none|awk '{print $3 }'|xargs docker rmi

如何停止所有正地运行的容器?

docker kill $(docker ps -q)

删除所有名字中带 “none” 关键字的镜像

docker rmi $(docker images | grep "none" | awk '{print $3}')

如何查看镜像支持的环境变量?

docker run IMAGE env

如何清理批量后台停止的容器?

docker rm -f $(docker ps -qa)

如何获取某个容器的PID信息

docker  inspect  --format '{{ .State.Pid }}' <CONTANINERID or NAME>

如何获取某个容器的IP地址?

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'  container_name_or_id

如何控制容器占用系统资源(CPU MEM)的份额?

在使用docker create命令创建容器或使用docker run创建并启动容器的时候,可以使用-c | --cpu-shares[=0] 参数来调整容器使用CPU的权重;使用 -m | --memory[=MEMORY]参数来调整容器使用内存的大小。

Docker容器环境变量设置方法

docker run --env <key>=<value> <IMAGE-ID>来修改环境变量

查看环境变量

docker inspect <CONTAINER-NAME> OR <CONTAINER-ID>

或

使用docker exec -it <CONTAINER-NAME> OR <CONTAINER-ID> env查看

 给镜像打tag

[root@localhost system]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

hello-world latest 4ab4c602aa5e 5 weeks ago 1.84kB

给镜像打tag(镜像的格式为,镜像仓库IP:端口/镜像名称)

[root@localhost system]# docker tag hello-world 172.16.50.37/repo-test/hello-world:hw20181019tag  # repo-test为harbor上的项目名称

查看镜像,发现已经生成

[root@localhost system]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

172.16.50.37/repo-test/hello-world hw20181019tag 4ab4c602aa5e 5 weeks ago 1.84kB

hello-world latest 4ab4c602aa5e 5 weeks ago 1.84kB

push镜像到仓库

[root@localhost system]# docker push 172.16.50.37/repo-test/hello-world  # repo-test为harbor上的项目名称

The push refers to repository [172.16.50.37/repo-test/hello-world]

428c97da766c: Pushed

hw20181019tag: digest: sha256:1a6fd470b9ce10849be79e99529a88371dff60c60aab424c077007f6979b4812 size: 524
posted @ 2019-05-08 12:00  番茄土豆西红柿  阅读(180)  评论(0编辑  收藏  举报
TOP