Docker installation method

Time:2020-11-23

centos8

Official documents

Set up repository

1. If the storage driver uses devicemapper, it needs to rely on device mapper persistent data and lvm2. (if not, please ignore this step.)

$ yum install -y yum-utils device-mapper-persistent-data lvm2

# OR

$ dnf install -y device-mapper-persistent-data lvm2

2. Set up a stable repository (alicloud source), official Repository:https://download.docker.com/linux/centos/docker-ce.repo

#Yum config manager depends on Yum utils 
$ yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# OR

$ dnf config-manager --add-repo=http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

Note: DNF is a package management tool provided by centos8. It is an upgraded version of Yum. DNF is used instead of Yum below

Installing docker CE

1. Installation

#View installable versions
$ dnf list docker-ce --showduplicates | sort -r
#Install the specified version
$ dnf -y install docker-ce-<VERSION_STRING>
#Install the latest version
$ dnf -y install docker-ce

If the following error occurs, please install the new version containerd.io

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
#Install new version containerd.io 
# https://download.docker.com/linux/centos/7/x86_64/stable/Packages/ontainerd.io-1.2.13-3.2.el7.x86_64.rpm
$ dnf -y install dnf install http://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.2.el7.x86_64.rpm

#Install docker CE 
$ dnf -y install docker-ce

2. Manage docker

#Start
$ systemctl start docker

#Close
$ systemctl stop docker

#Start up automatically
$ systemctl enable docker

3. Uninstall

$ dnf remove docker-ce docker-ce-cli containerd.io
#Specified version
$ dnf remove docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
#Uninstall old version
$ yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

Delete mirror and container files/var/lib/docker/(default storage address)

docker-compose

  • Download from GitHub
#To install a different version of compose, replace 1.25.4 with the version of compose you want to use.
$ curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
#Increase execution authority
$ chmod +x /usr/local/bin/docker-compose
  • Download from daocloud (fast)
$ curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
#Increase execution authority
$ chmod +x /usr/local/bin/docker-compose

docker & firewalld

If run firstdockerdRerunfirewalld, which will cause docker to fail to work normally and the internal container cannot access the network normally

Solution:

First:Modify docker network mode to host

  • docker run

Adding parameters when running containers–network=host

$ docker run --network=host ...
  • docker compose
network_mode: "host"

The second type:Replace firewalld with iptables (recommended)

#See if firewalld is enabled
$ systemctl status firewalld
#Stop firewalld
$ systemctl stop firewalld
#Disable firewalld (otherwise it will start again after restarting the system)
$ systemctl disable firewalld
#Check to see if iptables is installed
$ dnf list installed | grep iptables-services
#If not, install it
$ dnf -y install iptables-services
#Restart iptables
$ systemctl restart iptables
#Set auto start
$ systemctl enable iptables
#Restart docker
systemctl restart docker

The third kind:Turn off the firewall

#See if firewalld is enabled 
$ systemctl status firewalld 
#Stop firewalld 
$ systemctl stop firewalld
#Disable firewalld (otherwise it will start again after restarting the system) 
$ systemctl disable firewalld
#Restart docker
$ systemctl restart docker

Alicloud container image acceleration service

Improve the speed of acquiring docker image (login to get it)

Recommended Today

Method of hiding version number and web page cache time in nginx

Nginx Optimization — Hide version number and page cache time Configure nginx to hide version number In the production environment, we need to hide the version number of nginx to avoid security Leakage of loopholes View method Use Fiddler I to check the nginx version number on the Windows client Using “curl – I URL” […]