As the world moves towards containerizing services using Docker, being able to install Docker on production machines running software such as CentOS/Fedora/RHEL also becomes important. However, when you install it using Docker’s official guide, the installation either simply doesn’t work or will cause dependency issues later, not allowing you to cleanly update your system. Here, we will show you how to install Docker on CentOS from the official repositories without causing these issues.
Step 1: Remove old versions of Docker
Older Docker package versions were called docker
or docker-engine
. To ensure none of these are on your system which will cause problems in the next steps, you should remove them from the system.
sudo dnf remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
It’s fine if the command returns that none of the packages were installed, you can move on.
Step 2: Add Docker repository
Using the yum-utils package, add Docker’s stable repository to your system package manager.
sudo dnf install yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Step 3: Install Docker on CentOS/RHEL
This step is where the magic happens. On a clean installation, CentOS comes with versions of dependencies that are not compatible with newer versions of Docker engine. The command will remove all incompatible packages automatically and install the appropriate and compatible dependencies to work with Docker.
sudo dnf remove podman
sudo dnf install docker-ce docker-ce-cli containerd.io --allowerasing
If this command doesn’t work, you can substitute --allowerasing
with --nobest
but be advised this will install Docker with the dependency issue.
Optional: enable Docker systemd service on startup
Chances are that if the power goes out or for some reason the server must reboot, you want your containerized services to start up again by themselves. To do this, simply enable (and start) the Docker Engine systemd service.
sudo systemctl enable --now docker
That’s it! By now, you have learned how to install Docker on CentOS and have a working installation! Additionally, you will be able to update your system without encountering the dependency error that we discussed earlier.