一、系统要求
Docker 支持 64 位版本 CentOS 7/8,并且要求内核版本不低于 3.10。 CentOS 7 满足最低内核的要求,但由于内核版本比较低,部分功能无法使用,并且部分功能可能不太稳定。
二、卸载旧版本
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
三、安装
安装依赖包:
yum install -y yum-utils
添加 yum
软件源:
yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo
如果需要测试版本的 Docker 请执行以下命令:
yum-config-manager --enable docker-ce-test
更新 yum
软件源缓存,并安装 docker-ce
。
yum install docker-ce docker-ce-cli containerd.io
四、使用
启动docker
systemctl enable docker&&systemctl start docker
建立 docker 用户组
出于安全考虑,一般 Linux 系统上不会直接使用 root
用户使用docker。需要使用 docker
的用户加入 docker
用户组。
建立 docker
组:
groupadd docker
将当前用户加入 docker
组:
usermod -aG docker $USER
将用户test加入用户docker
组:
gpasswd -a test docker
测试 Docker 是否安装正确
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/