博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

docker 常用命令

Posted on 2018-03-21 10:50  bw_0927  阅读(115)  评论(0)    收藏  举报
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)



docker stop preserves the container in the docker ps -a list (which gives the opportunity to commit it if you want to save its state in a new image).

It sends SIGTERM first, then, after a grace period, SIGKILL.

docker rm will remove the container from docker ps -a list, loosing its "state" (the layered filesystems written on top of the image filesystem).
It cannot remove a running container (unless called with -f, in which case it sends SIGKILL directly).

In term of lifecycle, you are supposed to stop the container first, then remove it. It gives a chance to the container PID 1 to collect zombie processes.

 

 

docker rmi $(docker images -q --filter "dangling=true")    //删除

 

docker tag dfbc6474fb7d url_of_repo/image:v1                           把dfbc6474fb7d 的image重命名为url_of_repo/image:v1  

docker push url_of_repo/image:v1           

 

docker top container_id

 

 

docker build时,如果层没发生变化,默认会使用cache。  --no-cache 强制不使用cache

如果某一层变了,不管下面后续的层是否变过,后面的层都会重新编译。因此尽量把不变的层靠前放

 

RUN 命令后最好加上set -ex ,出现错误及早发现,不加的话出现错误很蛋疼,找不到