This is the second day of my participation in the August More text Challenge. For details, see: August More Text Challenge

If ❤️ my article is helpful, welcome to like, follow. This is the greatest encouragement for me to continue my technical creation. More past articles in my personal column

Note on installing Docker for Linux and encountering version problems

Experimental environment Centos 7

Linux minor version update

Docker has requirements for Linux versions (minor versions >300 or so). An early version may cause the following: For example, the port is mapped but the range is invalid

Find out which version of the Linux kernel is running on your system

$ uname -srm
Linux 3.10.0-327.el7.x86_64 x86_64
Copy the code

Linux 3.10.0-327.el7.x86_64 x86_64 3 – Kernel version.10 – Major revision. 0-957 – Minor revision.

Example Query the latest version that can be upgraded

$ yum list kernel Loaded plugins: fastestmirror Determining fastest mirrors * base: mirrors.ustc.edu.cn * elrepo: mirror-hk.koddos.net * epel: hkg.mirror.rackspace.com * extras: mirrors.ustc.edu.cn * updates: Mirrors.ustc.edu.cn base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/4) : base/7/x86_64/group_gz | 153 kB 00:00:00 (2/4): extras/7/x86_64/primary_db | 242 kB 00:00:00 (3/4): 7 / x86_64 / base/primary_db | 6.1 MB 00:00:01 (4/4) : 7 / x86_64 / updates/primary_db | 9.5 MB 00:00:01 Installed Packages kernel. X86_64 3.10.0-327. El7 @ anaconda kernel. X86_64 X86_64 3.10.0-1160.36.2.el7 updates 3.10.0-1160.36.2.el7 updates 3.10.0-1160.36.2.el7 updatesCopy the code

You can upgrade to 3.10.0-1062.12.1.el7 by running the yum update -y kernel command

Restart the system

6 Run the sudo init command to restart the system and check the Linux kernel version

$ uname -srm
Linux 3.10.0-1160.36.2.el7.x86_64 x86_64
Copy the code

Uninstall the older version of Docker

Is Docker installed on the system? If it is useless, uninstall it and reinstall it

$RPM - qa | grep docker docker - ce - cli - 20.10.7-3. El7. X86_64 docker - ce - rootless - extras - 20.10.7-3. El7. X86_64 Docker - ce - 20.10.7-3. El7. X86_64 docker - scan plugin 0.8.0-3. El7. X86_64# remove docker
$ yum remove docker \
      docker-client \
      docker-client-latest \
      docker-common \
      docker-latest \
      docker-latest-logrotate \
      docker-logrotate \
      docker-engine 

Copy the code

Install the Docker repository

The official reference: docs.docker.com/engine/inst…

Required software packages: yum-utils, device-mapper-persistent-data, and LVM2

$ yum install -y yum-utils \
      device-mapper-persistent-data \
      lvm2
Copy the code

Set up a stable repository (for downloading Docker)

$ yum-config-manager \
        --add-repo \
        https://download.docker.com/linux/centos/docker-ce.repo
Copy the code

Docker Engine-Community Docker Engine-Community

$ yum install docker-ce docker-ce-cli containerd.io
Copy the code

Check the current version. If the version data exists, the installation is successful

$docker -v Docker version 20.10.7, build F0DF350Copy the code

Configure domestic mirroring acceleration

"Accelerator address:" https://y5krm9wr.mirror.aliyuncs.com "modify the configuration file: 】 sudo mkdir -p/etc/docker sudo tee/etc/docker/daemon. Json < < -'EOF'
    {
      "registry-mirrors": ["https://y5krm9wr.mirror.aliyuncs.com"]
    }
    EOF
    sudo systemctl daemon-reload
    sudo systemctl restart docker
Copy the code

Start Docker and check if it started successfully.

# Start and close DockerSudo systemctl start docker sudo systemctl stop docker or sudo service docker start sudo service docker stop# Check whether the startup is successfulView the local image sudo docker images or run the hello-world image sudo docker run Hello-worldCopy the code

Set automatic startup upon startup

Docker belongs to the underlying support software. If you need to manually input commands for restarting Docker every time you start up, it is very troublesome, so it is generally set to start up automatically after starting up.

# Check whether it starts automatically upon startup
    systemctl list-unit-files | grep enableOr systemctl list - unit - files | grep docker# Automatically starts after startup
    sudo systemctl enable docker  
Copy the code