This is an instruction of installation Docker on CentOS 7.
Adding the Docker repository
We should download the repository file https://download.docker.com/linux/centos/docker-ce.repo and put it into
/etc/yum.repos.d/.
Also, we can do it in a more automatic way using yum-config-manager.
Install the yum-utils package (which provides the yum-config-manager utility) and set up the repository.
sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo https://download.docker.com/linux/centos/docker-ce.repo
Installing Docker
The Docker Engine package is called docker-ce.
sudo yum install docker-ce
Package docker-ce-cli will be installed as a dependency.
sudo systemctl start docker
sudo systemctl enable docker
Also, we can install Docker Compose:
sudo yum install docker-compose-plugin
Check installation
sudo docker version
It shows a version of a client and server. Also, it shows a version of Go’s language, that was used during compilation.
Example:
Client: Docker Engine - Community
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
Built: Mon Jun 6 23:05:12 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.17
API version: 1.41 (minimum version 1.12)
Go version: go1.17.11
Git commit: a89b842
Built: Mon Jun 6 23:03:33 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.6
GitCommit: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
runc:
Version: 1.1.2
GitCommit: v1.1.2-0-ga916309
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Another way to check installation is to run some container:
sudo docker container run hello-world
Manage Docker without sudo
The Docker daemon binds to a Unix socket instead of a TCP port.
By default, that Unix socket is owned by the user root and other users can only access it using sudo.
If you don’t want to preface the docker command with sudo, add users to the group docker.
When the Docker daemon starts, it creates a Unix socket accessible by members of the docker group.
sudo usermod -aG docker andrew
Restart Docker:
sudo systemctl restart docker
Log out and log back in so that your group membership is re-evaluated.
Verify that everything works without sudo:
docker run hello-world
Starting the Docker daemon
The Docker daemon (dockerd) creates, runs, and monitors containers and stores images. On most Linux systems systemd starts it for you:
sudo systemctl start docker
Enable it at boot:
sudo systemctl enable docker
You can also run docker daemon directly, but systemd is the usual approach.
Changing the storage driver
Restart the daemon with a different storage driver if the kernel supports it:
docker daemon -s overlay
Use --graph or -g to set Docker’s root directory — sometimes required so storage sits on the right filesystem (for example docker daemon -s btrfs -g /mnt/btrfs_partition).
To make the change permanent, edit the service unit or defaults file for your distro (on older Ubuntu, DOCKER_OPTS in /etc/default/docker).
See Storage drivers for driver trade-offs.
SELinux on Red Hat systems
On RHEL, CentOS, or Fedora, SELinux may block Docker with opaque Permission denied errors.
Check the mode:
sestatus
If Current mode is enforcing, switch to permissive mode (logs violations but does not block):
sudo setenforce 0
For production, configure SELinux policies for Docker instead of leaving enforcing disabled permanently.
Andrew Dorokhov