How to Install or Upgrade Docker on CentOS
January 09, 2021
Whether you want to install Docker on CentOS or you want to upgrade Docker engine to the latest version, this article will guide you through. Should be pretty simple. At the time of this article, I am installing docker engine version 20 on CentOS 8.
Some linux operating systems are pretty straight-forward when installing or upgrading docker. For CentOS, you have to remove some pre-installed packages to allow installing docker dependencies.
Cleanup
Remove installed packages
Run the following commands to make sure you have a clean fresh environment for a new docker installation:
sudo yum remove docker docker-client \
docker-client-latest \
docker-common docker-latest \
docker-latest-logrotate \
docker-logrotate docker-engine \
&& dnf remove docker-ce
If packages not found, it is fine. We just want to make sure those are uninstalled, if existed
Installation
Install the latest Docker version
Now the following commands will install the latest docker version on your machine. So go ahead and do what we are all good at; copy and past ;)
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io --allowerasing
You can check docker official docs for more details.
Did you also face a problem with a broken repo?
- If you faced a problem with the repo, or got an error with something like:
> sudo yum install docker-ce docker-ce-cli containerd.io
created by dnf config-manager from file:///root/ 0.0 B/s | 0 B 00:00
Errors during downloading metadata for repository 'root_':
- Curl error (37): Couldn't read a file:// file for file:///root/repodata/repomd.xml [Couldn't open file /root/repodata/repomd.xml]
Error: Failed to download metadata for repo 'root_': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
- Then it is most probably a repo got corrupted because of what so ever. You can just fix it with:
sudo dnf clean all && rm -r /var/cache/dnf
- And remove this broken repo, in my case
root_
was the corrupted repo. Delete it by running:\ don’t forget to change root_.repo to your broken repo name
rm /etc/yum.repos.d/root_.repo
Final steps
- After running everything successfully (yay), execute:
sudo systemctl start docker
- To enable auto-start docker daemon after each reboot: (please do it)
sudo systemctl enable docker