安装

操作系统要求

  • 您需要 CentOS 7 或 8 的维护版本。存档版本不受支持或测试。
  • centos-extras必须启用存储库。此存储库默认启用,但如果您已禁用它,则需要重新启用它
  • 推荐使用overlay2存储驱动。

卸载旧版本
旧版本的 Docker 被称为dockerdocker-engine. 如果安装了这些,请卸载它们以及相关的依赖项。

1
2
3
4
5
6
7
8
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine

设置存储库

1
sudo yum install -y yum-utils
1
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

安装 Docker 引擎

1
sudo yum install docker-ce docker-ce-cli containerd.io

安装 Docker 引擎指定版本

1
2
3
4
# 查看版本
yum list docker-ce --showduplicates | sort -r
# 安装指定版本
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

启动 Docker

1
sudo systemctl start docker

测试是否正常安装 此命令下载测试映像并在容器中运行它。当容器运行时,它会打印一条消息并退出。

1
sudo docker run hello-world

指令

用法

1
docker [OPTIONS] COMMAND

选项

容器的自给自足运行时

1
2
3
4
5
6
7
8
9
10
11
    --config string      客户端配置文件的位置(默认“/root/.docker”)
-c, --context string 用于连接到守护程序的上下文的名称(覆盖 DOCKER_HOST 环境变量和使用“docker context use”设置的默认上下文)
-D, --debug 启用调试模式
-H, --host list 要连接的守护程序套接字
-l, --log-level string 设置日志级别(“调试”|“信息”|“警告”|“错误”|“致命”)(默认“信息”)
--tls 使用 TLS; 由 --tlsverify 暗示
--tlscacert string 仅由该 CA 签名的信任证书(默认为“/root/.docker/ca.pem”)
--tlscert string TLS 证书文件的路径(默认为“/root/.docker/cert.pem”)
--tlskey string TLS 密钥文件的路径(默认为“/root/.docker/key.pem”)
--tlsverify 使用 TLS 并验证远程
-v, --version 打印版本信息并退出

管理命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
app*        Docker App (Docker Inc., v0.9.1-beta3)
builder Manage builds
buildx* Docker Buildx (Docker Inc., v0.7.1-docker)
config Manage Docker configs
container Manage containers
context Manage contexts
image Manage images
manifest Manage Docker image manifests and manifest lists
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
scan* Docker Scan (Docker Inc., v0.12.0)
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes

命令

运行 ‘docker COMMAND –help’ 以获取有关命令的更多信息。
要获得有关docker的更多帮助,请查看的指南https://docs.docker.com/go/guides/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
attach      Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes