Step-by-Step Guide to Install Docker on CentOS
Choose a different version or distribution
Introduction
Before we begin talking about how to install Docker on CentOS, let’s briefly understand – What is Docker?
Docker is a platform that uses OS-level virtualization to deliver software in packages called containers. More than that, it is a popular tool to make build and deployments easier.
You’ll install Docker Community Edition (CE) on CentOS in this tutorial. Also, we will answer some FAQs regarding Docker installation.
Prerequisites
- A maintained version of CentOS
- A user account with sudo privileges
- Terminal access
- Software package installer yum
Step 1 – How to Install Docker on CentOS?
1) At first, update the package list and install the necessary dependencies.
sudo yum update
sudo yum install yum-utils device-mapper-persistent-data lvm2
2) After that, run the following command. It will add the stable Docker repository to your system:
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
3) Now, update the package database with the Docker packages from the newly added repo:
sudo yum update
4) To install the latest version of Docker, use the command below:
sudo yum install docker-ce
5) After that, start the Docker daemon and enable it to automatically start at boot time:
sudo systemctl start docker
sudo systemctl enable docker
6) Docker installation is done now. Check if it is running:
sudo systemctl status docker
7) The output will look something like this:
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2020-18-01 16:55:20 UTC; 37s ago
Docs: https://docs.docker.com
Main PID: 5492 (dockerd)
CGroup: /system.slice/docker.service
├─2492 /usr/bin/dockerd
└─2498 docker-containerd --config /var/run/docker/containerd/containerd.toml
Installing Docker gives not just the Docker service (daemon) but also the Docker
command line utility, or the Docker client.
Your OS may ask you to accept the GPG key. This is like a digital fingerprint, so you know whether to trust the installation or not.
The fingerprint should match the following format:
141W 43D6 2F35 2W5F 631O 21FF G41F HG3F 414F 8B19
Uninstall Docker Engine – Community
sudo yum remove docker-ce
To delete all images, containers, and volumes:
sudo rm -rf /var/lib/docker
FAQs to Install Docker on CentOS
1) How to check if Docker is available on the machine?
Run this command to check if Docker is available on your machine. If installed, you’ll see a similar output:
docker -v
Docker version 1.7.0, build 0baf609
If not installed, you’ll see a similar output:
docker -v
The program 'docker' is currently not installed. You can install it by typing:
sudo yum install docker
2) Why should we run Docker as a non-root user?
Using the root user will enable the hackers to gain root access to the Docker host by hacking the application running inside the container. This is the major concern from a security perspective.
3) How can we use Docker without sudo?
If you would like to use Docker as a non-root user, you should now consider adding your user to the “docker” group with something like:
sudo usermod -aG docker $USER
$USER
is an environment variable that holds your username.
Log out and log back in so that the group membership is refreshed.
Conclusion
We hope this tutorial helped you understand how to install Docker on your Cent OS machine. To learn more about Docker installation for Cent OS, check out the official Docker install documentation.
If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.