您的位置:首页 > 运维架构 > Docker

Docker technical notes

2015-12-25 13:11 671 查看
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:

杀死所有正在运行的容器

复制代码代码如下:

docker kill $(docker ps -a -q)

删除所有已经停止的容器

复制代码代码如下:

docker rm $(docker ps -a -q)

删除所有未打 dangling 标签的镜像

复制代码代码如下:

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

删除所有镜像

复制代码代码如下:

docker rmi $(docker images -q)

为这些命令创建别名

复制代码代码如下:

# ~/.bash_aliases

# 杀死所有正在运行的容器.

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

[code]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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: