Uninstall the previous version

Older versions of Docker are called Docker or Docker-Engine. If you have installed these programs, uninstall them and their associated dependencies.

$ sudo 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 Engine – Community

Before you install the Docker Engine-Community on a new host for the first time, you need to set up the Docker repository. After that, you can install and update Docker from the repository.

Set up the warehouse

Install required software packages. Yum-utils provides yum-config-manager, and the device Mapper storage driver requires device-mapper-persistent-data and LVM2.

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

Use the following command to set up the stable repository.

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

Install the Docker Engine – Community

Install the latest versions of Docker engine-Community and Containerd, or go to the next step to install specific versions:

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

If you are prompted to accept the GPG key, select Yes.

Docker is not started by default after installation. In addition, a Docker user group has been created, but there is no user under this user group.

To install a specific version of Docker engine-Community, list the available versions in the repository, then select and install:

1. List and sort the versions available in your repository. This example sorts the results by version number, from highest to lowest.

$docker yum list - ce - showduplicates | sort - r docker - ce. X86_64 3:18. 09.1-3. El7 docker - ce - stable docker - ce. X86_64 3:18.09.0-3.el7 docker-ce-stable docker-ce. X86_64 18.06.1. Ce-3. el7 docker-ce-stable docker-ce. X86_64 18.06.0.ce-3.el7 docker-ce-stableCopy the code

Install a specific version by its full package name, which is the package name (docker-ce) plus the version string (the second column), from the first colon (:) to the first hyphen, separated by a hyphen (-). For example, docker-CE-18.09.1.

$ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
Copy the code

Start the Docker.

$ sudo systemctl start docker
Copy the code

Verify that Docker engine-Community is installed correctly by running the Hello-world image.

$ sudo docker run hello-world
Copy the code