How to install Docker on CentOS 7
In this article, I will explain how to install Docker engine on your CentOS 7 machine. If you are interested in Docker or if you want to start to learn Docker, this article will be helpful. You’ll be able to install the Docker engine on your CentOS machine on your own after reading this article.
*If you have a different version of CentOS, this instruction possibly doesn’t work.
Table of Contents
Step1: set up the repository
First, run the commands below.
$ sudo yum install -y yum-utils $ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
When you run the first command, you’ll probably be asked to input the password of the root user. In that case, just input the password and push the enter key.
Step1.5: handle the timeout error
When I run the second command, I got an error below. If you don’t get this error, you can skip to the next section.
Could not fetch/save url https://download.docker.com/linux/centos/docker-ce.repo to file /etc/yum.repos.d/docker-ce.repo: [Errno 12] Timeout on https://download.docker.com/linux/centos/docker-ce.repo: (28, 'Operation timed out after 30001 milliseconds with 0 out of 0 bytes received')
This error message says
[Errno 12] Timeout on https://download...., so this error is due to the timeout. To fix this error, we need to modify the yum configuration file a little bit. The default timeout setting is configured to be 30 seconds, and we’ll change this to be 300 seconds. Run the command below and add a line to the configuration file.
$ vi /etc/yum.conf
Then, add a line
timeout=300 at the bottom of the file. You can save and exit the text editor by inputting
Esc key + :wq + Enter key.
[main] cachedir=/var/cache/yum/$basearch/$releasever keepcache=0 debuglevel=2 logfile=/var/log/yum.log exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 installonly_limit=5 bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum distroverpkg=centos-release # This is the default, if you make this bigger yum won't see if the metadata # is newer on the remote and so you'll "gain" the bandwidth of not having to # download the new metadata and "pay" for it by yum not having correct # information. # It is esp. important, to have correct metadata, for distributions like # Fedora which don't keep old packages around. If you don't like this checking # interupting your command line usage, it's much better to have something # manually check the metadata once an hour (yum-updatesd will do this). # metadata_expire=90m # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d timeout=300
Now the timeout limitation is updated. Let’s try the second command again. This time, the command could complete.
Step2: Install the Docker Engine
Next, run the command below and install the Docker Engine.
$ sudo yum install -y docker-ce docker-ce-cli containerd.io
Step3: Activate the Docker Engine
Now the installation is done, so the next step is to activate the Docker Engine. Run the command below and activate it.
$ sudo systemctl start docker $ sudo systemctl enable docker
Then, run the command below.
$ docker version
This command shows us the version of the Docker Engine. If you get the output like below, it means you could successfully install and activate Docker!
Client: Docker Engine - Community Version: 20.10.3 API version: 1.41 Go version: go1.13.15 Git commit: 48d30b5 Built: Fri Jan 29 14:34:14 2021 OS/Arch: linux/amd64 Context: default Experimental: true Server: Docker Engine - Community Engine: Version: 20.10.3 API version: 1.41 (minimum version 1.12) Go version: go1.13.15 Git commit: 46229ca Built: Fri Jan 29 14:32:37 2021 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.4.3 GitCommit: 269548fa27e0089a8b8278fc4fc781d7f65a939b runc: Version: 1.0.0-rc92 GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff docker-init: Version: 0.19.0 GitCommit: de40ad0
If you have any troubles with this installation process, I think the official document below will be a good reference.