How to Install Docker Compose with Docker on Ubuntu 22.04. Docker Compose is a simple tool that provides a way to orchestrate multiple containers to work together which makes deployment using a
In this guide you are going to learn how to install Docker compose and create a new application using docker compose on Ubuntu 22.04.
- SSH access to your server
- Docker installed, see how to install Docker on Ubuntu 22.04 LTS.
Install Docker Compose
Once you have Docker installed you can proceed to install Docker Compose.
Here we shall install latest version of Docker Compose from the official GitHub repository.
sudo curl -L https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
Set up correct permissions to the downloaded file.
sudo chmod +x /usr/local/bin/docker-compose
Verify the installation using the following command.
Output Docker Compose version v2.5.0
Now Docker Compose is installed successfully and you can start running containers.
Use Docker Compose
Docker Compose allows you to use YAML file to define multiple container applications. With the YAML file you can run, build and configure all containers.
Create a project directory and navigate inside that directory.
mkdir docker-project cd docker-project
Create a YAML file. This is a basic example of the yaml file for hello world .
sudo nano docker-compose.yml
Paste the following contents and save the file.
version: '3.9' services: hello-world: image: hello-world:latest
Ctrl + X followed by
Enter to save the file and exit.
Now you can execute the following command to pull the hello word image from Docker Hub.
Supercharge your Linux Administration Career with completed training course and get your dream job.
You will receive an output similar to this.
Output [+] Running 2/2 ⠿ hello-world Pulled 1.5s ⠿ 2db29710123e Pull complete 0.4s [+] Running 2/2 ⠿ Network docker-project_default Created 0.1s ⠿ Container docker-project-hello-world-1 Created 0.1s Attaching to docker-project-hello-world-1 docker-project-hello-world-1 | docker-project-hello-world-1 | Hello from Docker! docker-project-hello-world-1 | This message shows that your installation appears to be working correctly. docker-project-hello-world-1 | docker-project-hello-world-1 | To generate this message, Docker took the following steps: docker-project-hello-world-1 | 1. The Docker client contacted the Docker daemon. docker-project-hello-world-1 | 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. docker-project-hello-world-1 | (amd64) docker-project-hello-world-1 | 3. The Docker daemon created a new container from that image which runs the docker-project-hello-world-1 | executable that produces the output you are currently reading. docker-project-hello-world-1 | 4. The Docker daemon streamed that output to the Docker client, which sent it docker-project-hello-world-1 | to your terminal. docker-project-hello-world-1 | docker-project-hello-world-1 | To try something more ambitious, you can run an Ubuntu container with: docker-project-hello-world-1 | $ docker run -it ubuntu bash docker-project-hello-world-1 | docker-project-hello-world-1 | Share images, automate workflows, and more with a free Docker ID: docker-project-hello-world-1 | https://hub.docker.com/ docker-project-hello-world-1 | docker-project-hello-world-1 | For more examples and ideas, visit: docker-project-hello-world-1 | https://docs.docker.com/get-started/ docker-project-hello-world-1 | docker-project-hello-world-1 exited with code 0
Now the hello-world image is pulled from Docker Hub and docker-compose creates a container, attaches and runs the program.
You can see all the containers using the following command.
docker ps -a
Output CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3a83d1a6be58 hello-world:latest "/hello" 2 minutes ago Exited (0) 2 minutes ago docker-project-hello-world-1
Now you have made a deployment using Docker Compose.
Now you have learned how to install and use Docker Compose with Docker on Ubuntu 22.04.
Thanks for your time. If you face any problem or any feedback, please leave a comment below.