清除未使用的卷
「How To Remove Docker Containers, Images, Volumes, and Networks」
清除没有使用的卷:docker system prune –volumes
镜像保存和载入
Docker镜像保存save、加载load
How to see docker image contents
有时候某些镜像无法下载,可以先 docker save 为 tar 文件,然后将 tar 文件 docker load 到本地中。
有时候我们需要查看镜像内容。通常运行它,然后使用ls命令即可。但是某些镜像并不包含这些命令,比如traefik:1.7.14镜像。我们可以使用dive命令查看,或者docker save然后使用tar命令解压。
向运行中的容器添加卷
-「How can I add a volume to an existing Docker container?」
方法一:先docker commit容器,然后重新创建容器,创建镜像的时候使用-v选项添加卷;
方法二:使用docker cp命令向容器中复制文件;
方法三:基于块设备的高级玩法:「~jpetazzo/Attach a volume to a container while it is running」
删除所有停止的容器
# docker container rm $(docker container ls -a -q)
查看镜像的CMD和ENTRYPOINT值
「How can I determine ENTRYPOINT & CMD are on an image?」
# docker image inspect <image id>
# 当–net=host时
「Ports aren’t showing up in docker ps, and are failing for registrator. #15537」
使用主机网络时,端口映射没有用处的,因为容器正在使用主机的网络堆栈。
就是说,当你的应用程序在监听端口时,它正在侦听主机的端口。
# 构建镜像是忽略文件
「COPY with docker but with exclusion」
相关链接
「Docker Tip #10: Project Structure with Multiple Dockerfiles and Docker Compose」
「Best practices for writing Dockerfiles」
「Use multi-stage builds」
参考文献
Remove Untagged Images From Docker