1. 基本概念

类比于编程中的概念

  • 镜像 <=> 类
  • 容器 <=> 实例
  • 仓库 <=> 包管理

2. 命令例子

1
2
3
4
5
6
7
8
9
# Simple format
docker pull REGISTRY_NAME[:TAG]
# REGISTRY_NAME = USER_NAME/IMAGE_NAME
# Default USER_NAME = library(Official images)
# Default TAG = latest

# E.g.
docker pull mysql:5.6
docker pull phusion/baseimage:master
  • Show images (default hides intermediate images)/container (default shows just running)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Aliases - Images
docker images # Shortest
docker image ls
docker image list

# Aliases - Containers
docker ps # Shortest
docker container ls
docker container list

# Arguments usages - Images
docker images -a # a => all
docker images -q # q => quiet

# Arguments usages - Containers
docker ps -a # a => all
docker ps -q # q => quiet
docker ps -s # s => size
  • Remove images/containers
1
2
3
4
5
6
7
8
9
10
11
12
13
# Aliases - Images
docker rmi IMAGE_ID # Shortest
docker image rm IMAGE_ID

# Aliases - Containers
docker rm CONTAINER_ID # Shortest
docker container rm CONTAINER_ID

# Practical usages
docker rmi $(docker images -q) # Remove all images except intermediate images
docker rmi $(docker images -aq) # Remove all images
docker rm $(docker ps -q) # Remove all containers except not running containers
docker rm $(docker ps -aq) # Remove all containers

(未完待续)

评论