In our previous tutorial we’ve seen How To Install Docker on Ubuntu 16.04 18.04 / 19.04. Now we’ll move further to Install Docker Compose on different Linux distributions like Ubuntu, Debian, CentOS and Debian.
What is Docker Compose?
Docker Compose is a tool that provides us the facility to define and run multi-container Docker application. A YAML file is the configuration file used to configure your application’s services.
So, we are going to Install Docker Compose in as much details as possible so you can easily understand and Install it. For this Installation we’ll check Github API releases page for our project. After it we’ll pull out the latest binary file for our Installation process. So, follow the below steps to move further.
Step 1: Installing Latest Docker Compose on Linux
You must have installed Curl on your system for this operation.
Access to the root or user with root privileges.
---- CentOS / RHEL -----
$ sudo yum -y install curl
---- Debian / Ubuntu ----
$ sudo apt install -y curl
----- Fedora -----
$ sudo dnf -y install curl
After Installing curl move to the next point which is Downloading the latest Compose on your Linux Machine.
curl -s https://api.github.com/repos/docker/compose/releases/latest \
| grep browser_download_url \
| grep docker-compose-Linux-x86_64 \
| cut -d '"' -f 4 \
| wget -qi -
Make sure to make binary file executable.
chmod +x docker-compose-Linux-x86_64
Now, move the file to your PATH.
sudo mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
Check the version you’ve installed.
Step 2: Configure Compose Command-line completion.
Compose has command completion for the bash & zsh shell.
Place the completion script in /etc/bash_completion.d/
sudo curl -L https://raw.githubusercontent.com/docker/compose/master/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
Source the file or re-login to enjoy completion features.
Download the completion script in your ~/.zsh/completion/
mkdir -p ~/.zsh/completion
curl -L https://raw.githubusercontent.com/docker/compose/master/contrib/completion/zsh/_docker-compose > ~/.zsh/completion/_docker-compose
Include the directory in your $fpath by adding in ~/.zshrc
Double check that compinit is loaded or load it by adding in ~/.zshrc.
autoload -Uz compinit && compinit -i
After-it reload your shell.
exec $SHELL -l
Step 3: Test Docker Compose Installation
Make a file for testing docker compose.
Copy & paste the below data in the file.
Start the containers services.
$ docker-compose up -d
Starting root_php_1 … done
Starting root_web_1 … done
Show running Containers
$ docker-compose ps
Name Command State Ports
root_php_1 docker-php-entrypoint php-fpm Up 9000/tcp
root_web_1 nginx -g daemon off; Up 0.0.0.0:8080->80/tcp
$ docker-compose stop
Stopping root_web_1 … done
Stopping root_php_1 … done
$ docker-compose rm -f
Going to remove root_web_1, root_php_1
Removing root_web_1 … done
Removing root_php_1 … done