Easy Tutorial
❮ Debian Docker Install Docker Swarm ❯

CentOS Docker Installation

Docker supports the following 64-bit CentOS versions:


Automatic Installation Using Official Script

Run the following command to install:

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

Alternatively, you can use the one-click installation command from DaoCloud:

curl -sSL https://get.daocloud.io/docker | sh

Manual Installation

Uninstall Old Versions

Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them along with associated dependencies.

$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

Install Docker Engine-Community

Using the Docker Repository for Installation

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

Set up the repository

Install the required packages. yum-utils provides the yum-config-manager utility, and device mapper storage driver requires device-mapper-persistent-data and lvm2.

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

Use the following command to set up the stable repository.

Using the Official Source (slower)

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

You can choose some domestic source addresses:

Aliyun

$ sudo yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

Tsinghua University Source

$ sudo yum-config-manager \
    --add-repo \
    https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

Install Docker Engine-Community

Install the latest version of Docker Engine-Community and containerd, or go to the next step to install a specific version:

$ sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

If prompted to accept the GPG key, select yes.

>

Multiple Docker Repositories?

If multiple Docker repositories are enabled, installation or updates without specifying a version in the yum install or yum update command will always install the highest version, which may not suit your stability needs.

Docker is installed but not started by default. The docker group is created, but no users are added to this 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 results by version number (from highest to lowest).

    $ yum list docker-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-stable
    
  2. Install a specific version by its full package name, which is the package name (docker-ce) plus the version string (second column) starting from the first colon (:) up 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
    

Start Docker.

$ sudo systemctl start docker

Verify that Docker Engine-Community is installed correctly by running the hello-world image.

$ sudo docker run hello-world

Uninstall Docker

Remove the package:

yum remove docker-ce

Remove images, containers, configuration files, etc.:

rm -rf /var/lib/docker
❮ Debian Docker Install Docker Swarm ❯