Install Docker Compose v2 system-wide

Install Docker Compose v2 system-wide
Photo by Dayne Topkin / Unsplash

In this post I'm going to show you how you can install Docker Compose version 2 on a Linux system and register a systemctl service.

Install Docker Compose

Docker Compose releases are available at the following Git Hub repository https://github.com/docker/compose/releases. This means we easily can download the binary for e.g. a 64 bit Linux operating system. In the example below I use curl to perform the download and store it at /usr/libexec/docker/cli-plugins/docker-compose.

sudo curl -SL https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-linux-x86_64 -o /usr/libexec/docker/cli-plugins/docker-compose

Now we need to make sure that the binary is executable.

sudo chmod 755 /usr/libexec/docker/cli-plugins/docker-compose

Install a Systemctl Service

Now I want to run my docker composition as a service to make sure the composition starts when the operating system starts. Therefore I create a new file myservice.service at /etc/systemd/system.

[Unit]
Description=My service with docker compose
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
RemainAfterExit=true
WorkingDirectory=<path to your Docker composition
ExecStart=/usr/libexec/docker/cli-plugins/docker-compose up -d --remove-orphans
ExecStop=/usr/libexec/docker/cli-plugins/docker-compose down

[Install]
WantedBy=multi-user.target

Finally we register the new service by executing sudo systemctl enable myservice.service. Et voilà, the service is registered and can be started using sudo systemctl start myservice.service.

Silvio Wangler

Silvio Wangler

Embrach, Switzerland