docker-ce_install_centos75
1.docker 在线安装
1.1.卸载旧版 docker 软件
- 软件名称一般为 docker,docker-io 或者 docker-engine
- 卸载完成还需要查看并清理旧的 docker 数据目录,包含镜像,容器,网络等配置
sudo yum remove docker
docker-client
docker-client-latest
docker-common
docker-latest
docker-latest-logrotate
docker-logrotate
docker-engine
rpm -qa |grep docker*
ll /var/lib/docker/
1.2.配置 docker 的 yum 仓库
- 安装依赖,配置仓库
yum install yum-utils device-mapper-persistent-data lvm2 -y
- 配置软件库
# 官方库
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 可选:阿里云仓库
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 可选:清华源仓库
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo
- 参考地址:
https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.3e221b11ncDNOT
- 可选配置:禁用 nightly 和 test 库
# 如果想简洁安装可以执行以下命令禁用其他库
yum-config-manager --disable docker-ce-nightly docker-ce-test
- 备注:
1)yum-utils 提供 yum-config-manager 和 utility 工具
2)即使不使用 nightly 库或 test 库也必须安装
3)建议上午安装,如果下载超时可以手动下载 rpm 包,然后上传到 /etc/yum.repos.d/ 目录
1.3.安装 docker-ce
- 安装最新版 docker-ce
yum makecache fast
yum install docker-ce
yum install docker-ce docker-ce-cli containerd.io docker-compose -y
- 注意:
1)如果提示需要接受 GPGkey,需要与以下 fingerprint 匹配:
060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
2)安转完成会自动创建 docker 用户组,需要手动创建 docker 用户
- 安装指定版本的 docker-ce
# 查询 docker-ce 版本列表
yum list docker-ce --showduplicates
yum list docker-ce --showduplicates | sort -r # 倒序排列
# 安装指定版本 docker
# yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
# 例如:
# yum install docker-ce-18.06.1.ce-3.el7 docker-ce-cli-18.06.1.ce-3.el7 containerd.io
- 升级 docker-ce
yum -y upgrade <包名>
1.4.启动 docker 并配置开机自启动
systemctl enable docker
systemctl status docker
systemctl start docker
ps -ef |grep docker
# 检查确认 docker 是否安装成功
docker run hello-world
- 实例演示:
-------------------
[root@zuiyoujie tools] yum list docker-ce --showduplicates
Loaded plugins: fastestmirror
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
Installed Packages
docker-ce.x86_64 3:19.03.8-3.el7 @docker-ce-stable
Available Packages
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.10-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.11-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.12-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.13-3.el7 docker-ce-stable
-------------------------
[root@zuiyoujie tools]# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9db2ca6ccae0: Pull complete
Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc
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/engine/userguide/
------------------------
2.离线安装 docker-ce
-
下载 RPM 包进行安装(网络不好时使用)
-
RPM包下载地址:
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-19.03.5-3.el7.x86_64.rpm
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-19.03.5-3.el7.x86_64.rpm
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
2.1.下载 docker-ce 的 rpm 包
mkdir -p /opt/tools
cd /opt/tools
yum install docker-ce-19.03.5-3.el7.x86_64.rpm docker-ce-cli-19.03.5-3.el7.x86_64.rpm containerd.io-1.2.6-3.3.el7.x86_64.rpm
systemctl start docker
systemctl enable docker
ps -ef |grep docker
docker run hello-world
3.使用 docker 脚本进行安装
- 不是很推荐
curl -fsSL https://get.docker.com -o get-docker.sh
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.
---------------------------------------
4.卸载清理docker-ce软件
# 卸载 docker-ce 软件
yum remove docker-ce docker-ce-cli containerd.io
# 清理 docker-ce 数据
rm -rf /var/lib/docker