Install Docker on CentOS

Make sure you can download files from the Internet using wget.

Uninstall the pre-installed versions of Docker, if there are some:

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

Install dependencies for Docker:

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

Add repository to download Docker from to the installation manager:

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

Install Docker:

sudo yum install docker-ce

Configure Docker, if necessary.
For instance, if you need to use your custom subnet for the default Docker bridge network interface, create the /etc/docker/daemon.json file with the following content. Please use /24 as mask.:

{
  "bip": "172.26.0.1/24"
}

Start the Docker daemon:

sudo systemctl start docker

Test if the Docker daemon runs:

docker ps

You should see an empty list of running containers and no error message.

Install Docker Compose on CentOS

Make sure the Docker is installed (see the guide above)

Download and install Docker compose with the following commands:

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

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

Make sure /usr/bin is inside the PATH variable:

PATH=$PATH:/usr/bin

Check that Docker Compose is installed using the following command:

docker-compose --version

In order to work with Docker Compose, you need to have a docker-compose.yml with all images you want to pull and run specified inside. This file is recommended to be located inside the /opt/docker-compose folder:

mkdir -p /opt/docker-compose
vi /opt/docker-compose/docker-compose.yml

Ensure containers start on boot

Change the SELinux context for docker-compose temporarily so that it can be executed by systemd

chcon -t bin_t /usr/local/bin/docker-compose

Persist the changes

semanage fcontext -a -t bin_t /usr/local/bin/docker-compose

Create a systmd startup script

vi /etc/systemd/system/docker-compose-up-on-startup.service

Assuming that /opt/docker-compose is the directory with your docker-compose, add this contents

[Unit]
Description=Docker Compose Application Service
Requires=docker.service
After=docker.service

[Service]
User=root
Type=oneshot
RemainAfterExit=yes
Environment=COMPOSE_HTTP_TIMEOUT=10000
WorkingDirectory=/opt/docker-compose
ExecStart=/usr/local/bin/docker-compose up -d
ExecStop=/usr/local/bin/docker-compose down
TimeoutStartSec=0

[Install]
WantedBy=multi-user.target