安装 Docker
删除旧版本
1
2
3
4
5
6
7
8
9
10
11
12
13
14sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
# 或者
sudo yum remove flannel docker* -y
sudo yum -y remove docker docker-common docker-selinux docker-engine docker-engine-selinux container-selinux docker-ce
sudo rm -rf /var/lib/docker
配置 repo
yum-config-manager
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
# 或者使用阿里云
sudo yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Optional
sudo yum-config-manager --enable docker-ce-edge
sudo yum-config-manager --enable docker-ce-test
sudo yum-config-manager --disable docker-ce-edgeyum 加速和代理
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# 加速配置(阿里云加速)
## 备份原来的yum源
cd /etc/yum.repos.d/
sudo mv CentOS-Base.repo CentOS-Base.repo_bak
## 获取阿里云yum源
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# sudo wget -e "http_proxy=192.168.123.1:1234" -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 代理配置
sudo sed -i '/^proxy=/d' /etc/yum.conf
sudo sh -c "echo proxy=http://192.168.123.1:1234 >> /etc/yum.conf"
sudo cat /etc/yum.conf
# 清除原有 yum 源缓存
sudo yum clean all
## 生成 yum 源缓存
sudo yum makecache
## 或者
sudo rm -f /var/lib/rpm/__*
sudo rpm --rebuilddb -v -v
sudo yum clean dbcache
sudo yum clean metadata
sudo yum clean rpmdb
sudo yum clean headers
sudo yum clean all
sudo rm -rf /var/cache/yum/timedhosts.txt
sudo rm -rf /var/cache/yum/*
sudo yum makecache
安装 docker
创建 docker 和 data 目录(可不创建,使用默认路径)
1
2
3
4
5
6
7
8docker 默认下载目录 /var/lib/docker/
sudo mkdir -p /data/docker/lib/docker
创建软连接
sudo ln -s /data/docker/lib/docker /var/lib/docker
删除软连接(注意:最后没有/,否则会把/var/lib/docker下的内容全部删除)
rm /var/lib/docker
sudo chmod 770 -R /var/lib/docker/
sudo chmod 777 -R /data/docker在线安装
1
2
3
4
5
6
7
8
9
10
11# 安装最新版本
sudo yum install docker-ce
#安装指定版本 docker
# 可以查看所有仓库中所有docker版本,并选择特定版本安装
yum list docker-ce --showduplicates | sort -r
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
sudo yum install docker-ce-<VERSION STRING>
# 或者
sudo curl https://releases.rancher.com/install-docker/20.10.sh | sh
sudo curl --proxy 192.168.123.1:1234 https://releases.rancher.com/install-docker/20.10.sh | sh
离线安装
1
2
3
4
5
6
7
8
9 # 需要按顺序执行
sudo yum install -y docker-ce-cli-19.03.12-3.el7.x86_64.rpm
# 下载路径:http://mirror.centos.org/centos/7/extras/x86_64/Packages/
sudo yum install -y container-selinux-2.107-3.el7.noarch.rpm
sudo yum install -y containerd.io-1.3.7-3.1.el7.x86_64.rpm
sudo yum install -y docker-ce-19.03.12-3.el7.x86_64.rpm
# 或者将以上 rpm 包放到一个文件夹,然后执行一下命令,会自动判断依赖
yum localinstall -y *.rpm
启动并加入开机启动
1
2
3
4
5
6
7
8
9
10# 启动 docker
sudo systemctl start docker
# 重启
sudo systemctl restart docker
# 停止运行 docker
sudo systemctl stop docker
# 开机启动
sudo systemctl enable docker
# 禁止开机启动
sudo systemctl disable docker版本锁定
1 | sudo yum install yum-plugin-versionlock |
- 将当前用户加入
docker
组,并重启docker
1 | sudo gpasswd -a ${USER} docker |
验证安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19$ docker version
Client:
Version: 18.06.1-ce
API version: 1.38
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:23:03 2018
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.06.1-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:25:29 2018
OS/Arch: linux/amd64
Experimental: false
Docker 配置代理
1 | # 配置 docker pull 代理 |
其中172.16.120.0/24
为宿主机 ip
Docker 配置加速源
1 | sudo rm -rf /etc/docker/daemon.json |
安装 docker-compose
1 | 安装 |
进入容器
1 | # centos |