1. Install docker ce
1.1 Description
The early version of Docker is called docker or docker-engine. Since March 1, 2017, Docker has been divided into two versions: CE (Community Edition) and EE (Enterprise Edition). The installation package has changed, and the installation method is slightly different from before. Different, it cannot be installed directly through yum.
1.2 Uninstall the old version
The content that will be preserved in this way /var/lib/docker/
, including images, containers, storage volumes and networks, if you do not want to keep historical information, delete the folder first:
yum remove docker docker-common docker-selinux docker-engine
1.3 Install docker dependency packages
yum install -y yum-utils device-mapper-persistent-data lvm2
1.4 Setting up the mirror warehouse
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
1.5 Update the yum package index
yum makecache fast
1.6 Install the latest version of docker ce
yum install docker-ce
1.7 Install the specified version of docker ce
# 查看版本列表
yum list docker-ce.x86_64 --showduplicates | sort -r
# 安装指定版本
yum install 18.03.0.ce-1.el7
1.8 Start docker
systemctl start docker
1.9 Set the docker service to start up (optional)
systemctl enable docker.service
1.10 Configure domestic mirror accelerator
I configured the Taobao mirror source, this is what I wrote before, paste a link, do not re-write: Solve the problem of slow speed when docker pulls mirrors from official warehouses
Method 1: Add and configure /etc/docker/daemon.json
Method 2: Edit the file: /usr/lib/systemd/system/docker.service , add after ExecStart=/usr/bin/dockerd: --registry-mirror=<accelerator address>
1.11 Testing
docker run hello-world
2. Script
#!/bin/bash
echo "---> 卸载原始镜像"
yum remove docker docker-common docker-selinux docker-engine -y
echo "---> 安装所需的软件包:yum-utils device-mapper-persistent-data lvm2"
yum install -y yum-utils device-mapper-persistent-data lvm2
echo "---> 命令设置 stable 镜像仓库"
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
echo "---> 更新 yum 软件包索引"
yum makecache fast
echo "---> 开始安装docker"
if [ ! -n "$1" ]
then
echo "未指定版本,安装最新版本docker-ce"
yum install docker-ce -y
else
echo "安装指定版本:docker-ce-$1"
yum install docker-ce-$1 -y
fi
echo "---> 成功安装docker"
echo "---> 备份并修改docker配置文件"
cp -f /usr/lib/systemd/system/docker.service /usr/lib/systemd/system/docker.service.bak
sed -i '/ExecStart=\/usr\/bin\/dockerd/ s/$/ -H tcp:\/\/0.0.0.0:2376 -H unix:\/\/\/var\/run\/docker.sock/' /usr/lib/systemd/system/docker.service
# 这里换成自己的加
echo "---> 配置镜像加速器"
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"]
}
EOF
echo "重启docker及其守护进程"
systemctl daemon-reload
systemctl restart docker