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 \

Install dependencies for Docker:

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

Add repository to download Docker from to the installation manager:

sudo yum-config-manager \
   --add-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": ""

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 "$(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:


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

Description=Docker Compose Application Service

ExecStart=/usr/local/bin/docker-compose up -d
ExecStop=/usr/local/bin/docker-compose down