Skip to content

Instantly share code, notes, and snippets.

@blazewicz
Last active January 4, 2024 18:14
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save blazewicz/04e666ae1f25387c8b291d81b12c550c to your computer and use it in GitHub Desktop.
Save blazewicz/04e666ae1f25387c8b291d81b12c550c to your computer and use it in GitHub Desktop.
Install latest docker-compose on Debian, Ubuntu or Raspberry Pi OS (Raspbian)
#!/bin/bash
set -x
# This script with documentation is available at: https://gist.github.com/blazewicz/04e666ae1f25387c8b291d81b12c550c
## 1. install required dependencies with apt
apt update && apt install python3-venv python3-dev libffi-dev libssl-dev
## 2. create directory for docker-compose's virtualenv
mkdir -p /opt/local/docker-compose
## 3. create virtualenv in which we will install docker-compose
python3 -m venv /opt/local/docker-compose/venv
## 4. install docker-compose, this may take some time becase some dependecies has to be compiled
/opt/local/docker-compose/venv/bin/pip install --upgrade pip
/opt/local/docker-compose/venv/bin/pip install docker-compose
## 5. create a symlink so our fresh docker-compose is available in the $PATH
ln -s /opt/local/docker-compose/venv/bin/docker-compose /usr/local/bin/docker-compose

docker-compose installation guide

This steps will guide you to install docker-compose inside its own, isolated virtual environment. This way you can install latest docker-compose without mangling your system Python installation.

Installing docker-compose with following steps:

# these steps work with both python and python3
sudo apt install python3-pip python3-dev libffi-dev libssl-dev
sudo pip3 install docker-compose

Is going to overlay python packages installed by apt with dependencies installed along with docker-compose. This may cause compatibility issues with Python packages installed by apt, and may lead to some hard to fix issues with entire system.

DO NOT EVER MIX sudo AND pip UNLESS YOU ARE ABSOLUTELY SURE ABOUT THAT!

Python virtualenv was created precisely for the purpose of dependency isolation.

Installing within virtualenv is recommended in the official docker-compose installation guide.

Installation

You can copy docker-compose-install.sh contents into a file, set exection flag and run as sudo:

chmod u+x docker-compose-install.sh
sudo ./docker-compose-install.sh

Or follow instructions below to do it manually.

1. install required dependencies with apt

sudo apt update
sudo apt install python3-venv python3-dev libffi-dev libssl-dev

2. create directory for docker-compose's virtualenv

sudo mkdir -p /opt/local/docker-compose

3. create virtualenv in which we will install docker-compose

sudo python3 -m venv /opt/local/docker-compose/venv

4. install docker-compose

This may take some time becase some dependecies have to be compiled.

sudo /opt/local/docker-compose/venv/bin/pip install --upgrade pip
sudo /opt/local/docker-compose/venv/bin/pip install docker-compose

5. create a symlink on $PATH

This is necessary so our new docker-compose is available on the $PATH, and makes it possible to simply call docker-compose.

sudo ln -s /opt/local/docker-compose/venv/bin/docker-compose /usr/local/bin/docker-compose

Upgrading

You can invoke this any time, and it will install newest available version of docker-compose.

sudo /opt/local/docker-compose/venv/bin/pip install --upgrade docker-compose

Uninstalling

To uninstall simply remove virtualenv directory and the symlink.

sudo rm -rf /usr/local/bin/docker-compose /opt/local/docker-compose
@maelcum
Copy link

maelcum commented Jul 14, 2020

[sudo] /opt/local/docker-compose/venv/bin/pip install --update pip throws the error no such option: --update on a clean 2020-05-27-raspios-buster-lite-armhf installation.

@blazewicz
Copy link
Author

@maelcum, sorry my mistake, pip uses --upgrade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment