# How To Install Docker Compose on Linux How do I install Docker Compose on Ubuntu 22.04/20.04/18.04 | Debian 11/10 | CentOS 8 | Fedora 36/35/34/33/32?. This guide will show you how to Install the Latest Docker Compose on Linux. Compose is a tool for defining and running multi-container Docker application. A YAML file is used to configure your application's services. This post aims to be a concise instructional step-by-step guide for developers and SysAdmins seeking to setup Docker Compose on Linux. We will check the Github API releases page for the project, and pull the latest binary file. ## How To Install Docker Compose on Linux You need curl and wget installed on your system for this operation. And definitely, access to the Terminal as a user with sudo privileges. ``` ### CentOS / RHEL ### sudo yum -y install curl wget ### Debian / Ubuntu ### sudo apt update sudo apt install -y curl wget ### Fedora ### sudo dnf -y install curl wget ``` Once curl has been installed, download 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 the binary file executable. ``` chmod +x docker-compose-linux-x86_64 ``` Move the file to your PATH. ``` sudo mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose ``` Confirm version. ``` $ docker-compose version Docker Compose version v2.11.2 ``` Add user to docker group: ``` sudo usermod -aG docker $USER newgrp docker ``` ## Configure Compose Command-line completion Compose has [command completion](https://en.wikipedia.org/wiki/Command-line_completion) for the bash and zsh shell. ## For Bash users 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 feature. ``` source /etc/bash_completion.d/docker-compose ``` ## For Zsh users 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`: ``` fpath=(~/.zsh/completion $fpath) ``` Make sure `compinit` is loaded or do it by adding in `~/.zshrc`: ``` autoload -Uz compinit && compinit -i ``` Then reload your shell: ``` exec $SHELL -l ``` ## Test Docker Compose installation. Our comprehensive guide is on [Managing Docker Containers with Docker Compose](https://computingforgeeks.com/managing-docker-containers-with-docker-compose/) Create a test Docker Compose file. ``` vim docker-compose.yml ``` Add below data to the file. ``` version: '3' services: web: image: nginx:latest ports: - "8080:80" links: - php php: image: php:7-fpm ``` Start service containers. ``` $ docker-compose up -d Creating network "root_default" with the default driver Pulling php (php:7-fpm)... 7-fpm: Pulling from library/php b4d181a07f80: Pull complete 78b85dd8f014: Pull complete 8589b26a90be: Pull complete f5af5d641946: Pull complete 4611dfe4969e: Pull complete 8d335174dcfe: Pull complete e4ac2aba3855: Pull complete 1ec2992b064f: Pull complete d0702e432261: Pull complete 508ceaa40a86: Pull complete Digest: sha256:c5132fe8a019128a89bcc157f5e2b8544ea3078fb9aba076bfe27486f34b0fb5 Status: Downloaded newer image for php:7-fpm Pulling web (nginx:latest)... latest: Pulling from library/nginx b4d181a07f80: Already exists edb81c9bc1f5: Pull complete b21fed559b9f: Pull complete 03e6a2452751: Pull complete b82f7f888feb: Pull complete 5430e98eba64: Pull complete Digest: sha256:47ae43cdfc7064d28800bc42e79a429540c7c80168e8c8952778c0d5af1c09db Status: Downloaded newer image for nginx:latest Creating root_php_1 ... done Creating 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 /docker-entrypoint.sh ngin ... Up 0.0.0.0:8080->80/tcp,:::8080->80/tcp ``` Destroy containers ``` $ 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 ``` Go through Official[ Docker documentation](https://docs.docker.com/) and [Docker Compose documentation](https://docs.docker.com/compose/) to learn more. ### Best Docker Learning Courses: - [Docker Mastery: with Kubernetes +Swarm from a Docker Captain](https://click.linksynergy.com/deeplink?id=2sb89XJC/EQ&mid=39197&murl=https%3A%2F%2Fwww.udemy.com%2Fcourse%2Fdocker-mastery%2F) - [Docker for the Absolute Beginner -- Hands On -- DevOps](https://click.linksynergy.com/deeplink?id=2sb89XJC/EQ&mid=39197&murl=https%3A%2F%2Fwww.udemy.com%2Fcourse%2Flearn-docker%2F) - [Docker and Kubernetes: The Complete Guide](https://click.linksynergy.com/deeplink?id=2sb89XJC/EQ&mid=39197&murl=https%3A%2F%2Fwww.udemy.com%2Fcourse%2Fdocker-and-kubernetes-the-complete-guide%2F) - [Docker -- SWARM -- Hands-on -- DevOps](https://click.linksynergy.com/deeplink?id=2sb89XJC/EQ&mid=39197&murl=https%3A%2F%2Fwww.udemy.com%2Fcourse%2Flearn-docker-advanced%2F) - [Docker Swarm Mastery: DevOps Style Cluster Orchestration](https://click.linksynergy.com/deeplink?id=2sb89XJC/EQ&mid=39197&murl=https%3A%2F%2Fwww.udemy.com%2Fcourse%2Fdocker-swarm-mastery%2F) ### More guides: - [Ctop -- Top command for container metrics](https://computingforgeeks.com/top-command-for-container-metrics/) - [How to Install Portainer Docker UI manager](https://computingforgeeks.com/install-docker-ui-manager-portainer/) - [How To run Local Kubernetes clusters in Docker](https://computingforgeeks.com/how-to-run-local-kubernetes-clusters-in-docker/) - [Deploy Lightweight Kubernetes with MicroK8s and Snap](https://computingforgeeks.com/deploy-lightweight-kubernetes-with-microk8s-and-snap/) - [How to run Minikube on KVM](https://computingforgeeks.com/how-to-run-minikube-on-kvm/)