How to Install Docker Compose on Ubuntu 22.04 - Step-by-step tutorial
In this Docker tutorial series I will show the steps to install Docker Compose on your Ubuntu 22.04 system. This tutorial is applicable for both Desktop and Server Ubuntu 22.04 operating systems. You should have sudo access to the system to install Docker Compose on your operating system.
What is Docker Compose?
Docker Compose is a tool developed for running multiple docker container based applications in one go. For example if you have to run an Apache HTTP server and you want to use the Nginx as front end for the internet, then you can combine Nginx and Apache containers using the docker-compose.yml file and run it docker-compose. Here we use one YAML file to define the services (using one or more docker images) and run it using a single command.
In future tutorials we will show you many more examples of running
containerized applications using the docker-compose. This is one of the easiest
ways to run applications that use many dependent applications to run together.
We are going to learn two ways to install Docker Compose on Ubuntu 22.04. Ways
to install docker-compose:
- Install from Ubuntu Repository
- Install from Git build file
Now we will see these two ways of installing docker-compose on the ubuntu operating system. You can follow any of these two says to install docker-compose on your Ubuntu 22.04 operating system.
1. Install Docker compose from the Ubuntu Repository
It is very easy to install the Docker Compose from the Ubuntu 22.04 repository. You can simply run the following command to install this software on Ubuntu 22.04:
sudo apt install docker-compose
Above command will download the required library files and then download docker-compose on your Ubuntu 22.04. After installation you will be able to use the docker-compose tool for running your dockerized applications.
Here is the output of the above command:
roseindia@roseindia-VirtualBox:~/Desktop$ sudo apt install docker-compose [sudo] password for roseindia: Reading package lists... Done Building dependency tree... Done Reading state information... Done The following package was automatically installed and is no longer required: systemd-hwe-hwdb Use 'sudo apt autoremove' to remove it. The following additional packages will be installed: libpython3-stdlib python3 python3-attr python3-distutils python3-docker python3-dockerpty python3-docopt python3-dotenv python3-jsonschema python3-lib2to3 python3-minimal python3-pyrsistent python3-setuptools python3-texttable python3-websocket Suggested packages: python3-doc python3-tk python3-venv python-attr-doc python-jsonschema-doc python-setuptools-doc Recommended packages: docker.io The following NEW packages will be installed: docker-compose python3-attr python3-distutils python3-docker python3-dockerpty python3-docopt python3-dotenv python3-jsonschema python3-pyrsistent python3-setuptools python3-texttable python3-websocket The following packages will be upgraded: libpython3-stdlib python3 python3-lib2to3 python3-minimal 4 upgraded, 12 newly installed, 0 to remove and 161 not upgraded. Need to get 1,042 kB of archives. After this operation, 4,863 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 python3-minimal amd64 3.10.6-1~22.04 [24.3 kB] Get:2 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 python3 amd64 3.10.6-1~22.04 [22.8 kB] Get:3 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libpython3-stdlib amd64 3.10.6-1~22.04 [6,910 B] Get:4 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 python3-lib2to3 all 3.10.6-1~22.04 [77.6 kB] Get:5 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 python3-distutils all 3.10.6-1~22.04 [139 kB] Get:6 http://in.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-websocket all 1.2.3-1 [34.7 kB] Get:7 http://in.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-docker all 5.0.3-1 [89.3 kB] Get:8 http://in.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-dockerpty all 0.4.1-2 [11.1 kB] Get:9 http://in.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-docopt all 0.6.2-4 [26.9 kB] Get:10 http://in.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-dotenv all 0.19.2-1 [20.5 kB] Get:11 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 python3-attr all 21.2.0-1 [44.0 kB] Get:12 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 python3-setuptools all 59.6.0-1.2 [339 kB] Get:13 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 python3-pyrsistent amd64 0.18.1-1build1 [55.5 kB] Get:14 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 python3-jsonschema all 3.2.0-0ubuntu2 [43.1 kB] Get:15 http://in.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-texttable all 1.6.4-1 [11.4 kB] Get:16 http://in.archive.ubuntu.com/ubuntu jammy/universe amd64 docker-compose all 1.29.2-1 [95.8 kB] Fetched 1,042 kB in 2s (488 kB/s) (Reading database ... 196847 files and directories currently installed.) Preparing to unpack .../python3-minimal_3.10.6-1~22.04_amd64.deb ... Unpacking python3-minimal (3.10.6-1~22.04) over (3.10.4-0ubuntu2) ... Setting up python3-minimal (3.10.6-1~22.04) ... (Reading database ... 196847 files and directories currently installed.) Preparing to unpack .../00-python3_3.10.6-1~22.04_amd64.deb ... running python pre-rtupdate hooks for python3.10... Unpacking python3 (3.10.6-1~22.04) over (3.10.4-0ubuntu2) ... Preparing to unpack .../01-libpython3-stdlib_3.10.6-1~22.04_amd64.deb ... Unpacking libpython3-stdlib:amd64 (3.10.6-1~22.04) over (3.10.4-0ubuntu2) ... Preparing to unpack .../02-python3-lib2to3_3.10.6-1~22.04_all.deb ... Unpacking python3-lib2to3 (3.10.6-1~22.04) over (3.10.4-0ubuntu1) ... Selecting previously unselected package python3-distutils. Preparing to unpack .../03-python3-distutils_3.10.6-1~22.04_all.deb ... Unpacking python3-distutils (3.10.6-1~22.04) ... Selecting previously unselected package python3-websocket. Preparing to unpack .../04-python3-websocket_1.2.3-1_all.deb ... Unpacking python3-websocket (1.2.3-1) ... Selecting previously unselected package python3-docker. Preparing to unpack .../05-python3-docker_5.0.3-1_all.deb ... Unpacking python3-docker (5.0.3-1) ... Selecting previously unselected package python3-dockerpty. Preparing to unpack .../06-python3-dockerpty_0.4.1-2_all.deb ... Unpacking python3-dockerpty (0.4.1-2) ... Selecting previously unselected package python3-docopt. Preparing to unpack .../07-python3-docopt_0.6.2-4_all.deb ... Unpacking python3-docopt (0.6.2-4) ... Selecting previously unselected package python3-dotenv. Preparing to unpack .../08-python3-dotenv_0.19.2-1_all.deb ... Unpacking python3-dotenv (0.19.2-1) ... Selecting previously unselected package python3-attr. Preparing to unpack .../09-python3-attr_21.2.0-1_all.deb ... Unpacking python3-attr (21.2.0-1) ... Selecting previously unselected package python3-setuptools. Preparing to unpack .../10-python3-setuptools_59.6.0-1.2_all.deb ... Unpacking python3-setuptools (59.6.0-1.2) ... Selecting previously unselected package python3-pyrsistent:amd64. Preparing to unpack .../11-python3-pyrsistent_0.18.1-1build1_amd64.deb ... Unpacking python3-pyrsistent:amd64 (0.18.1-1build1) ... Selecting previously unselected package python3-jsonschema. Preparing to unpack .../12-python3-jsonschema_3.2.0-0ubuntu2_all.deb ... Unpacking python3-jsonschema (3.2.0-0ubuntu2) ... Selecting previously unselected package python3-texttable. Preparing to unpack .../13-python3-texttable_1.6.4-1_all.deb ... Unpacking python3-texttable (1.6.4-1) ... Selecting previously unselected package docker-compose. Preparing to unpack .../14-docker-compose_1.29.2-1_all.deb ... Unpacking docker-compose (1.29.2-1) ... Setting up libpython3-stdlib:amd64 (3.10.6-1~22.04) ... Setting up python3 (3.10.6-1~22.04) ... running python rtupdate hooks for python3.10... running python post-rtupdate hooks for python3.10... Setting up python3-pyrsistent:amd64 (0.18.1-1build1) ... Setting up python3-lib2to3 (3.10.6-1~22.04) ... Setting up python3-websocket (1.2.3-1) ... Setting up python3-dockerpty (0.4.1-2) ... Setting up python3-dotenv (0.19.2-1) ... Setting up python3-distutils (3.10.6-1~22.04) ... Setting up python3-attr (21.2.0-1) ... Setting up python3-texttable (1.6.4-1) ... Setting up python3-docopt (0.6.2-4) ... Setting up python3-setuptools (59.6.0-1.2) ... Setting up python3-docker (5.0.3-1) ... Setting up python3-jsonschema (3.2.0-0ubuntu2) ... Setting up docker-compose (1.29.2-1) ... Processing triggers for man-db (2.10.2-1) ... roseindia@roseindia-VirtualBox:~/Desktop$
Now you can check the version of your docker-compose by running following command on the terminal:
docker-compose --version
Here is the screenshot of the docker-compose version:
Above command shows the version of docker-compose installed on my system.
If you want to remove docker-compose from your system then you can run following command:
sudo apt remove docker-compose
This command will remove docker-compose from your Ubuntu 22.04 operating system. This command will also work if you are using any other version of Ubuntu Operating system. Here is the output of the command to remove docker-compose:
oseindia@roseindia-VirtualBox:~/Desktop$ sudo apt remove docker-compose [sudo] password for roseindia: Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages were automatically installed and are no longer required: python3-attr python3-docker python3-dockerpty python3-docopt python3-dotenv python3-jsonschema python3-pyrsistent python3-texttable python3-websocket systemd-hwe-hwdb Use 'sudo apt autoremove' to remove them. The following packages will be REMOVED: docker-compose 0 upgraded, 0 newly installed, 1 to remove and 167 not upgraded. After this operation, 510 kB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 197544 files and directories currently installed.) Removing docker-compose (1.29.2-1) ... Processing triggers for man-db (2.10.2-1) ... roseindia@roseindia-VirtualBox:~/Desktop$
So, also learned the command to remove docker-compose from your Ubuntu 22.04 system.
2. Install Docker compose from the git repository file
There is another distribution of the docker-compose on the git repository, which can be used to install the docker-compose on the Ubuntu 22.04 Desktop and Server operating system. The latest build of the docker-compose can be found at Releases · docker/compose (github.com). Here is the screen shot of the docker-compose release page:
You should visit the above docker compose release page and check the latest version and then update the version in the docker-compose install command.
The installation of docker-compose this way is easy and straightforward, you just have to download the executable and move it to the /usr/local/bin directory. After moving the file to this directory you can give the execute permission. After this you will be able to use docker-compose in your computer. At the time of writing of tutorial the docker-compose release version was v2.15.1. So, we have given the command to install docker-compose version v2.15.1.
Here is the command to download docker-compose version v2.15.1:
sudo curl -L "https://github.com/docker/compose/releases/download/v2.15.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Here is the screenshot of the above command:
Now the next step is to provide the execute permission of the file. You can make this file executable by running the following command:
sudo chmod +x /usr/local/bin/docker-compose
If you run the following command you will get the version of docker-compose:
docker-compose --version
Above command should display the version of docker-compose. In our case "Docker Compose version v2.15.1" message is displayed. So, this way you will be able to install docker-compose by downloading the build file from the git repository. If you want to remove the docker-compose then you have to run following command to remove the executable. Here is the command to remove docker-compose executable:
sudo rm /usr/local/bin/docker-compose
Above command will remove docker-compose from you Ubuntu 22.04 system. In this tutorial we have learned two methods of installing docker-compose on your Ubuntu operating system.
Check more Docker tutorials at Docker Tutorials section.