How to install Docker Engine on CentOS
Docker Engine is an open containerization program for Linux and other platforms. Docker Engine manages self-contained “containers” that operate similar to virtual machines. In this guide, we’ll go over how to install Docker Engine on CentOS.
Docker Engine only supports CentOS 7 and 8. Therefore, if you are using an older release of the operating system, you must upgrade before attempting to install Docker on your CentOS system.
Before we begin
Before setting up Docker Engine on CentOS, older Docker or Docker Engine versions need to be removed. The reason older releases of Docker must be uninstalled is that they can conflict with the release of Docker Engine being set up in this guide.
Thankfully, uninstalling older releases of Docker in CentOS is easy. To remove them, launch a terminal and use the yum remove command to get rid of the old packages.
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
After getting rid of the old packages from your CentOS system, you must set up the “centos-extras” software repository. This software repository is usually set up out of the box on CentOS, so there is no need to go over how to make it work here. However, if you’ve disabled this repo (for whatever reason), you must turn it back on before attempting to install Docker Engine on CentOS.
Setting up Docker Engine on Cent OS 7/CentOS 8
To start setting up Docker Engine on CentOS, you’ll need the “yum-utils” package. This package will give you access to the “yum-config-manager” tool, which you can use to set up the official Docker repo.
Open up a terminal window and use the yum install command to set up the “yum-utils” package on the system. Installation should be quick.
sudo yum install -y yum-utils
After setting up the “yum-utils” package on your CentOS system, use the yum-config-manager command to add the official Docker repository. Adding this repo will enable you to get the latest security updates and patches for Docker.
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
The Docker software repository is enabled on CentOS with the command above run. However, if you require the Docker nightly or the Docker test channel repo, you must enable them.
Docker CE Nightly repo
While it isn’t recommended to enable the nightly repository, you can do it if you need it. To enable the Docker CE Nightly repository on CentOS, use the following yum-config-manager command below in a terminal.
sudo yum-config-manager --enable docker-ce-nightly
If you’ve changed your mind and wish to disable the Docker CE Nightly software repository, run the yum-config-manager command, but add the –disable switch to it.
sudo yum-config-manager --disable docker-ce-nightly
Docker CE Test repo
If you wish to enable the Docker CE Test repository on CentOS, it is possible, although not recommended for production purposes. To set up this repo on your CentOS system, use the yum-config-manager command below in a terminal window.
sudo yum-config-manager --enable docker-ce-test
If you no longer wish to use the Docker CE Test repository on your CentOS system, it is possible to disable it. To shut off the Docker CE Test repository, run the yum-config-manager command below, but with the –disable switch.
sudo yum-config-manager --disable docker-ce-test
After setting up the Docker CE software repository on your CentOS system, use the yum list command to view available versions of Docker CE on the official Docker repository.
yum list docker-ce --showduplicates | sort -r
By running the yum list docker-ce –showduplicates command, you’ll see all versions of Docker CE available for installation. So, if you need a specific release of Docker CE, you can choose one from the list.
For example, to install version 3:18.09.1-3, you can specify it with the yum install command.
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
The installation process for Docker CE shouldn’t take long. Once it is set up on your CentOS system, you must enable it with Systemd. Then, using the systemctl start command, start up Docker on CentOS.
sudo systemctl start docker
In addition to starting up Docker on CentOS, you’ll also have to enable it at boot. Enabling Docker to start up at boot means that Docker CE will be ready to use even when CentOS is restarted.
sudo systemctl enable docker
If at any time you wish to stop Docker from running on CentOS, you can run the systemctl stop command below.
sudo systemctl stop docker
You’ll also be able to disable Docker from starting up when CentOS boots by running the systemctl disable command.
sudo systemctl stop docker
Once the Docker Engine system is set up on your CentOS system, you will need to test it to operate and run correctly. Run the docker run command to test out Docker Engine on your system.
sudo docker run hello-world