Install Docker on Ubuntu 22.04 (with Compose)

There are many ways to install docker on Ubuntu, which can be overwhelming. This post shows how to install Docker on Ubuntu 22.04 Jammy Jellyfish, with Docker Compose support.

Step 1: Update and Install Docker Dependencies

First, let us update our packages list and install the required docker dependencies.

sudo apt update


Then, use the following command to install the dependencies or pre-requisite packages.

sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release

Step 2: Add Docker Repository to APT Sources

First, let us get the GPG key which is needed to connect to the Docker repository. To that, use the following command.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Next, add the repository to the sources list. While you can also add it manually, the command below will do it automatically for you.

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

The above command will automatically fill in your release code name (jammy for 22.04, focal for 20.04, and bionic for 18.04).

Finally, refresh your packages again.

sudo apt update

If you forget to add the GPG key, then the above step would fail with an error message. Otherwise, let us get on with installing Docker on Ubuntu.

Step 3: Install Docker on Ubuntu/Debian Linux

In this Ubuntu Docker setup guide, we will install the docker-ce (and not docker.io package).

To install Docker on Ubuntu or Debian, use the following command:

sudo apt install docker-ce

This will download and install several hundred MBs of packages, as shown below.

Continue and the docker engine installation process should normally go through without any issues.

Step 4: Verify that Docker is Running on Ubuntu

There are many ways to check if Docker is running on Ubuntu. One way is to use the following command:

sudo systemctl status docker

You should see an output that says active for status.

INSTALL DOCKER-COMPOSE ON UBUNTU 22.04

Step 1: Check the Current Version of Docker Compose

As said before, the version of docker-compose packaged with the Linux distribution is probably old.

sudo apt search docker-compose

Checking the releases on Docker Compose GitHub, the last release is v2.14.1.

Step 2: Install Docker Compose on Ubuntu

Unlike Docker, there are no official repositories that you can add to easily install Docker Compose on Ubuntu.

First, download the latest version of Docker Compose using the following command:

sudo curl -L https://github.com/docker/compose/releases/download/v2.14.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

Change v2.14.1 to the current release number. Next, make it executable using the following command:

sudo chmod +x /usr/local/bin/docker-compose

That is it. Docker Compose should now be installed on your Ubuntu system.

Step 3: Check if Docker Compose is Installed

Let us check to make sure Docker Compose is installed and is available for us to use using:

docker-compose -v

If the installation was successful, you should see the docker compose version number as the output.

TIP TO ENCHANCE DOCKER EXPERIENCE

Add User to Docker Group

Running and managing docker containers requires sudo privileges. So this means you will have to type sudo for every command or switch to the root user account. But you can get around this by adding the current user to the docker group using the following command:

sudo usermod -aG docker ${USER}

You can replace ${USER} with your user name or just run the command as-is while you are logged in.

While this can be a minor security risk, it should be OK as long as other Docker security measures are in place.