有网安装 Docker 指定版本
有网安装 Docker
从 2017 年 3 月开始 docker 在原来的基础上分为两个分支版本: Docker CE 和 Docker EE。
Docker CE 即社区免费版,Docker EE 即企业版,强调安全,但需付费使用。
本文介绍 Docker CE 的安装使用。
参考文档 官网安装教程
移除旧的版本:
sudo yum remove -y docker docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
安装一些必要的系统工具:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum install -y containerd.io
添加软件源信息:
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新 yum 缓存:
sudo yum makecache fast
查看可用版本的 Docker-ce:
yum list docker-ce --showduplicates | sort -r
注意:如果需要只显示table版本,可以关闭测试版本的list:
sudo yum-config-manager --enable docker-ce-edge
sudo yum-config-manager --enable docker-ce-test
更新yum包索引
yum makecache fast
安装指定版本的docker-ce:
# 安装最新版本(推荐)
sudo yum install -y docker-ce
# 安装指定版本
sudo yum install -y docker-ce-18.06.0.ce-3.el7
报错:如果在安装指定版本的docker时显示需要安装指定版本的docker-ce-selinux依赖包,请安装:
yum install -y https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-18.06.0-ce
安装完毕查看docker的版本docker -v
就能看到Docker version 18.06.0-ce, build 0ffa825
安装完docker之后更改镜像的保存位置参考文章 (https://www.cnblogs.com/ejiyuan/p/12241998.html)
安装docker-compose(推荐使用Daocloud源)
# 不推荐用这个 好消息 docker 24.0.0之后就自带 docker compose 了
curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# 推荐用这个 最新版详见 https://get.daocloud.io/#install-docker
curl -L https://get.daocloud.io/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# curl -L https://get.daocloud.io/docker/compose/releases/download/v2.2.3/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose # 更新到2.x版本
chmod +x /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 617 0 617 0 0 373 0 --:--:-- 0:00:01 --:--:-- 373
100 11.1M 100 11.1M 0 0 368k 0 0:00:31 0:00:31 --:--:-- 444k
[root@operation ~]# chmod +x /usr/local/bin/docker-compose
[root@operation ~]# docker-compose version
docker-compose version 1.23.0-rc2, build 350a555e
docker-py version: 3.5.0
CPython version: 3.6.6
OpenSSL version: OpenSSL 1.1.0f 25 May 2019
安装完docker之后最好设置自己的镜像保存地址和开机自启动
# 1. 修改镜像保存的位置(建议修改)
mkdir /DataGrand/docker # 存放docker镜像的文件夹
vi /lib/systemd/system/docker.service # 加载配置,使docker可用并把镜像放在指定路径
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --graph /DataGrand/docker
systemctl daemon-reload # 修改之后需要重新加载docker配置
systemctl restart docker # 重启docker
systemctl enable docker # 将docker设置为开机重启
# 2. 将docker下载源换成国内的(更推荐)
vi /etc/docker/daemon.json
### 添加上这段
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
TIPS
一、安装出现报错内容
[root@localhost yum.repos.d]# yum install docker-ce docker-ce-cli containerd.io
Last metadata expiration check: 0:04:46 ago on Mon 16 Mar 2020 03:40:11 PM CST.
Package containerd.io-1.2.0-3.el7.x86_64 is already installed.
Error:
Problem: package docker-ce-3:19.03.8-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
- cannot install the best candidate for the job
- package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
- package containerd.io-1.2.13-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
- package containerd.io-1.2.2-3.el7.x86_64 is excluded
- package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
- package containerd.io-1.2.11-3.2.el7.x86_64 is excluded
- package containerd.io-1.2.12-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.6-3.2.el7.x86_64 is excluded
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
分析原因
看上面的内容,说的是containerd.io >= 1.2.2-3 ,意思就是 containerd.io 的版本必须大于等于 1.2.2-3
解决
1、要么就降低docker 的版本
2、如果不想降低docker 版本,那么就更新 containerd.io 的版本
[root@localhost ~]# yum install -y wget
[root@localhost ~]# wget https://download.docker.com/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
[root@localhost ~]# yum install -y containerd.io-1.2.6-3.3.el7.x86_64.rpm
[root@localhost ~]# yum install docker-ce
[root@localhost ~]# docker -v
# 大功告成
二、Docker服务启动报错:Job for docker.service failed because the control process exited with error
(https://blog.csdn.net/zhangbeizhen18/article/details/85239758)
懒人一键复制版
export REGISTRY_MIRROR=https://registry.cn-hangzhou.aliyuncs.com
# 卸载旧版本
sudo yum remove -y docker docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
# 设置 yum repository
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 安装并启动 docker
yum install -y docker-ce
mkdir /etc/docker || true
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["${REGISTRY_MIRROR}"]
}
EOF
mkdir -p /etc/systemd/system/docker.service.d
# Restart Docker
systemctl daemon-reload
systemctl enable docker
systemctl restart docker
# 查看docker版本信息
docker version
三 安装docker命令提示
yum install bash-completion -y
source /usr/share/bash-completion/bash_completion
# 永久 kubectl 补全
echo "source <(kubectl completion bash)" >> ~/.bashrc
source ~/.bashrc && su -