1. Mount a host directory into the docker container
sudo docker run -i -t -v /home/ubuntu:/mnt/ubuntu d55e /bin/bash
2. When pressing "ctrl + p + q" and the terminal returns to the parent shell, the container switched into a "stopped" status but still remains in the system background.
An improper "kill/stop" or "commit" to an container may result in a bunch of dangling containers and untagged images, which can quickly exhaust system resources (space/memory)
Solution:
杀死所有正在运行的容器
删除所有已经停止的容器
删除所有未打 dangling 标签的镜像
删除所有镜像
为这些命令创建别名
# 杀死所有正在运行的容器.
alias dockerkill='docker kill $(docker ps -a -q)'
# 删除所有已经停止的容器.
alias dockercleanc='docker rm $(docker ps -a -q)'
# 删除所有未打标签的镜像.
alias dockercleani='docker rmi $(docker images -q -f dangling=true)'
# 删除所有已经停止的容器和未打标签的镜像.
alias dockerclean='dockercleanc || true && dockercleani'
3. If a dangling image is the base layer of other tagged images, then command "docker rmi $(docker images -q -f dangling=true)" will fail.
See layer structure of iamges:
sudo docker images -tree
Option 1:
Delete all Images:
sudo docker rmi -f $(sudo docker images -a)
4. Push a repository/image to docker hub
sudo docker push repository_name:tag
5. Docker Image Rename
docker tag 1cf76 myUserName/imageName:0.1.0
7. Remove unwanted image tags
docker rmi repository/image_name:[tag]
(Note: Square Bracket is a notation for optional parameters)
output: Untagged: furaoing/ipsexl2tpd:latest (which means the this image has been untagged "xxxx", this tag had been just deleted)