Docker installation (official installation method)

Write in front

Because docker engine docker is not recommended officially, it cannot be installed, so now install docker CE.

Refer to official documents https://docs.rancher.cn/rancher2x/install-prepare/basic-environment-configuration.html#_4-1-docker%E5%AE%89%E8%A3%85

Installation procedure

1. Turn off the firewall

systemctl stop firewalld.service
systemctl disable firewalld.service

2. Add yum source

yum install ca-certificates ;
update-ca-trust;
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo-bak #backups

cat << 'EOF' > /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

EOF

3. Specify Docker version

export docker_version=18.09.9;

4. Delete the old docker component

apt-get remove docker docker-engine docker.io containerd runc -y;

5. Update apt source

apt-get update;

6. Comprehensively update and upgrade the system. It is recommended to upgrade it (optional)

apt-get -y upgrade;

7. Install necessary system tools

apt-get -y install apt-transport-https ca-certificates \
curl software-properties-common bash-completion gnupg-agent;

8. Install GPG certificate

curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | \
sudo apt-key add -;

9. Add Docker APT source

add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable";

10. Update and install Docker-CE

apt-get -y update;
install_version=$( apt-cache madison docker-ce | grep ${docker_version} | awk '{print $3}' );

11. Allow degraded installation

apt-get -y install docker-ce=${install_version} docker-ce-cli=${install_version} --allow-downgrades;

12. Add the current user to the docker group

usermod -aG docker $NEW_USER;

13. Set startup

systemctl start docker;
systemctl enable docker;

14. Clean up unnecessary dependencies

apt-get autoremove -y

Lock Docker version

Install the yum plugin versionlock plug-in

yum install yum-plugin-versionlock

Lock package

yum versionlock add docker-ce docker-ce-cli
yum versionlock add docker-ce docker-ce-cli
yum versionlock list

Unlock the specified package

Yum versionlock delete < package name >

Unlock all packages

yum versionlock clear

Keywords: CentOS Docker yum RPM

Added by 2gd-2be-2rue on Thu, 21 May 2020 17:57:29 +0300