Install Docker Compose
In this post I will install docker compose on my Ubuntu 22.04.2 LTS homeserver. The prerequisite for this is an already installed Ubuntu server as well as root and ssh access. It is useful if you followed the inital configuration for a fresh install from DigitalOcean.
Step 1: Download and install Docker
Connect via ssh to your server and use the following command to download from the official Docker repo:
Update your packages:
sudo apt update
Use apt packagaes over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Add offical Docker repo key to your system:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Add Docker repo to your APT sources:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Update your packages again:
sudo apt update
Make Ubuntu use the Docker repo:
apt-cache policy docker-ce
Finally, install Docker:
sudo apt install docker-ce
Verify Docker installation:
sudo systemctl status docker
The ouput should be similar to this, showing that the service is up and running:
root@homeserver:/home/# sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-05-19 10:47:41 UTC; 51s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 16822 (dockerd)
Tasks: 10
Memory: 25.4M
CPU: 373ms
Step 2: Download and install Docker Compose
Download Docker Compose directly from the Github repo:
mkdir -p /opt/docker/cli-plugins/
curl -SL https://github.com/docker/compose/releases/download/v2.3.3/docker-compose-linux-x86_64 -o /opt/docker/cli-plugins/docker-compose
Next, set the correct permissions so that the docker compose
command is executable:
chmod +x /opt/docker/cli-plugins/docker-compose
Verify correct installation:
docker compose version
The ouput should look something like this:
Output:
Docker Compose version v2.17.3
Docker Compose is now installed on your system and ready to use. In my next posts you will see how to set up a docker-compose.yml file for diffrent containers.
Update your Docker Compose:
Remove Docker Compose first when installed with curl:
sudo rm /opt/docker/cli-plugins/docker-compose
Get the latest version with grep and write the version number into a variable:
# curl + grep
VERSION=$(curl --silent https://api.github.com/repos/docker/compose/releases/latest | grep -Po '"tag_name": "\K.*\d')
Finally download the latest version to your favorite path which you can set here:
mkdir -p /opt/docker/cli-plugins/
DESTINATION=/opt/docker/cli-plugins/docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/${VERSION}/docker-compose-$(uname -s)-$(uname -m) -o $DESTINATION
chmod +x $DESTINATION
Verify new version:
docker compose version
Output:
Docker Compose version v2.18.1