Post Details

Install Docker and Docker-Compose on an Ubuntu server

Tutorials

Install Docker and Docker-Compose on an Ubuntu server

Another thing I have to do from time to time, and nearly always have to look up, is installing docker, and docker-compose on an Ubuntu server. Here's how I do it.

Ubuntu 20.04

This should work equally well on 18.04, or even 22.04.

  1. SSH into the box.
  2. Update APT and install pre-requisites

    sudo apt update
    sudo apt install apt-transport-https ca-certificates curl software-properties-common
    
  3. Add the Docker PPA repository

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
    

    For other distros, replace focal with the corresponding codename:

    Version Codename
    22.04 jammy
    20.04 focal
    18.04 bionic
    16.04 xenial
  4. (optional) Check to make sure that the docker package resolves to the Docker repo instead of the Ubuntu repo

    apt-cache policy docker-ce
    

    You should get something like the following:

    docker-ce:
      Installed: (none)
      Candidate: 5:19.03.9~3-0~ubuntu-focal
      Version table:
         5:19.03.9~3-0~ubuntu-focal 500
            500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
    
  5. And now the easy part; install docker and docker-compose

    sudo apt install -y docker-ce
    

    Check to see if it's running:

    sudo systemctl status docker
    

    You should see docker.service listed, and it should say Active: active (running)

    sudo apt install -y docker-compose
    

Next steps

After this, you should be able to use docker and docker-compose normally. If you don't want to sudo every command, you can add your user to the docker group following this article. It works for more than just Windows Subsystem for Linux as it implies.