How to install Docker & Docker Compose (Centos / RHEL)

Installing Docker

Centos

Now run this command. It will add the official Docker repository, download the latest version of Docker, and install it:

curl -fsSL https://get.docker.com/ | sh

After installation has completed, start the Docker daemon:

sudo systemctl start docker

Verify that it’s running:

sudo systemctl status docker

Make sure it starts at every server reboot:

sudo systemctl enable docker
To execute Docker Command without Sudo

If you need to add a user to the docker group that you’re not logged in as, declare that username explicitly using:

sudo usermod -aG docker username

RHEL

First remove older version of docker (if any):

sudo yum remove docker docker-common docker-selinux docker-engine-selinux docker-engine docker-ce

Next install needed packages

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

Install container-selinux. Check for latest version: http://mirror.centos.org/centos/7/extras/x86_64/Packages/.

sudo yum install -y \ http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.107-3.el7.noarch.rpm

Configure the docker-ce repo:

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Install docker-ce:

sudo yum install docker-ce

After installation has completed, start the Docker daemon:

sudo systemctl start docker

Verify that it’s running:

sudo systemctl status docker

Make sure it starts at every server reboot:

sudo systemctl enable docker

To execute Docker Command without Sudo

If you need to add a user to the docker group that you’re not logged in as, declare that username explicitly using:

sudo usermod -aG docker username

Installing Docker Compose

In order to get the latest release, take the lead of the Docker docs and install Docker Compose from the binary in Docker’s GitHub repository.

Check the current release and if necessary, update it in the command below:

sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Next, set the permissions to make the binary executable:

sudo chmod +x /usr/local/bin/docker-compose

To make sure that the path can be found make a symbolic link:

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Then, verify that the installation was successful by checking the version:

docker-compose --version

This will print out the version you installed:

Outputdocker-compose version 1.23.2, build 1110ad01