MYF

Get Docker CE for CentOS

参考文章: Get Docker CE for CentOS

系统要求

CentOS 7

移除旧版本

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

安装Docker

有三种方式可以安装

  • (推荐)使用仓库yum安装
  • RPM安装包安装,适用于不联网的机器
  • 自动化脚本

在此只介绍第1, 3种方式

Step 1: 安装必要的包

1
2
3
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2

Step 2: Setup稳定版的repo

1
2
3
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

Step 3(选做): 设置Edge版本和Test版本

1
2
3
4
sudo yum-config-manager --enable docker-ce-edge # 启动Edge
sudo yum-config-manager --enable docker-ce-test # 启动Test
sudo yum-config-manager --disable docker-ce-edge # 关闭Edge
sudo yum-config-manager --disable docker-ce-test # 关闭Test

Step 4: 安装

1
sudo yum install docker-ce

Step 5: 显示可用版本

1
yum list docker-ce --showduplicates | sort -r

Step 6: 启动

1
sudo systemctl start docker

Step 7: 验证

1
sudo docker run hello-world

通过脚本一键安装:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh

<output truncated>

If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

sudo usermod -aG docker your-user

Remember to log out and back in for this to take effect!

WARNING: Adding a user to the "docker" group grants the ability to run
containers which can be used to obtain root privileges on the
docker host.
Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
for more information.

卸载Docker

1
2
sudo yum remove docker-ce # 移除Docker包
sudo rm -rf /var/lib/docker # 移除Images, containers, volumes, or customized configuration files

权限管理

Continue to Post-installation steps for Linux to allow non-privileged users to run Docker commands and for other optional configuration steps.