Skip to content

Instantly share code, notes, and snippets.

@ai2ys
Last active October 21, 2022 13:36
Show Gist options
  • Save ai2ys/6e0191e1f924a67b9d2b0ea017d83d77 to your computer and use it in GitHub Desktop.
Save ai2ys/6e0191e1f924a67b9d2b0ea017d83d77 to your computer and use it in GitHub Desktop.
Ubuntu 20.04 - Install docker-compose

Install docker-compose on Ubuntu 20.04

I tried different installation methods via

  1. curl which failed because of a non existing URL
  2. apt-get which worked but the installed version does not GPU access
  3. pip which worked and the installed version does GPU access

Below the tried methods in detail.

❌ Installing via curl - failed because of URL (404)

Following the instructions from https://docs.docker.com/compose/install/ resulted in the following error when trying to run docker-compose afterwards.

# instructions from link above
sudo curl -L "https://github.com/docker/compose/releases/download/v1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

# trying to run docker-compose afterwars
docker-compose
# resulted in 
/usr/local/bin/docker-compose: line 1: Not: command not found

The URL that gets created in the first line of the installation instructions does not exist, which can be checked as follows.

# URL from the first command of the installation instructions
url_to_check="https://github.com/docker/compose/releases/download/v1.29.2/docker-compose-$(uname -s)-$(uname -m)"
# checking if URL exits
echo $(curl -s --head -w %{http_code} $url_to_check -o /dev/null)
# results in 
404

Installing via apt-get

The installation succeeded processing the following.

# install docker-compose using apt-get
sudo apt-get update
sudo apt-get install docker-compose
# 2022-01-15 installed got version: 
# docker-compose version 1.25.0, build unknown

The installed version is unsufficient for GPU support, which requires v2.3 or v1.28.+, referring to https://docs.docker.com/compose/gpu-support/

✔️ Installing via pip

# python 

# installing python3-pip
sudo apt-get update
sudo apt-get install python3-pip
# or just update pip in case it is already installed
sudo pip install --upgrade pip

# installing docker-compose
sudo pip install docker-compose~=1.29.2
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

💡 Uninstalling docker-compose depending on the installation method

# installed via apt-get
sudo apt-get remove docker-compose

# installed via curl
sudo rm /usr/local/bin/docker-compose
sudo rm /usr/bin/docker-compose

# installed via pip (without venv)
sudo pip uninstall docker-compose
sudo rm /usr/bin/docker-compose

Trying out the GPU support with docker-compose

# assigning a number of GPUs to the container
version: "3.8"
services:
  test_nvidia_smi_count:
    image: nvidia/cuda:11.0-base
    command: nvidia-smi    
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
docker-compose run test_nvidia_smi_count

# results in:
Creating project_test_nvidia_smi_count_run ... done
Sun Jan 16 17:52:22 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 495.29.05    Driver Version: 495.29.05    CUDA Version: 11.5     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA TITAN RTX    On   | 00000000:65:00.0 Off |                  N/A |
| 41%   28C    P8     4W / 280W |     97MiB / 24219MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+
# assigning specific GPU to container by its index
version: "3.8"
services:            
  test_nvidia_smi_device_ids:
    image: nvidia/cuda:11.0-base
    command: nvidia-smi    
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              device_ids: ['0']
              capabilities: [gpu]
docker-compose run test_nvidia_smi_device_ids

# results in:
Creating project_test_nvidia_smi_device_ids_run ... done
Sun Jan 16 17:51:42 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 495.29.05    Driver Version: 495.29.05    CUDA Version: 11.5     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA TITAN RTX    On   | 00000000:65:00.0 Off |                  N/A |
| 41%   28C    P8     3W / 280W |     97MiB / 24219MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment