Home Posts Docker & Docker Compose Installation

Docker & Docker Compose Installation

Calendar Icon (date post was published) published on  28 Dec 2020
Calendar Icon with Refresh Icon (date post was updated) updated on  15 Oct 2021

This post is the entrypoint into a series of articles describing several setups with Docker and Docker Compose.

As a first step, both applications have to be installed on the desired machine. This is actually rather simple and follows more or less the instructions given on the respective documentations of Docker and Docker Compose. This guide explains the installation on a Linux (Ubuntu) system.

Docker Engine

At first, we are going to install the Docker Engine. The following commands will do so:

sudo apt update
# the following packages are most likley already installed on your machine
sudo apt install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
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 \
   $(lsb_release -cs) \
   stable"
# actual installation of docker
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
# verify installation
sudo docker run hello-world

A few words about these commands:

  • First we install some required packages, but they should be usually already installed on a standard Ubuntu installation.
  • Then, we add the (public key) of the Docker-Repository, add the repository and install the Docker engine.
  • Finally, by starting the hello-world test container we verify the installation of Docker.

Docker Compose

Docker Compose allows you to easily create a set of “connected/linked” containers and makes it very easy to configure the container (network, environment, etc.).

New Compose Version

A new Docker Compose version (v2) has been released lately. The installation process differs from the old one. Both are described below.

Docker Compose v2

The following commands install the compose extension globally, i.e. for every user. The official documentation also describes how to install it only for one user.
Check out the latest v2 version on the GitHub Releases page and replace the version in the command below (v2.0.1) by the latest:

# download binary
mkdir -p /usr/local/lib/docker/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.0.1/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose

# make binary executable
chmod +x ~/.docker/cli-plugins/docker-compose

# verify installation
docker compose version

Note that for Docker Compose v2 the "base command" changed from docker-compose to docker compose. Docker offers the utility tool Compose Switch allowing you to use the old command style with the new v2 version.

Docker Compose v1 (Legacy)

Check out the latest v1 version on the GitHub Releases page and replace the version in the command below (1.29.2) by the latest:

# download compose binary
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# make it executable
sudo chmod +x /usr/local/bin/docker-compose
# check that docker compose works
docker-compose --version

Updates

For Docker, run sudo apt update and either sudo apt upgrade (to upgrade all your system packages) or just sudo apt install docker-ce docker-ce-cli containerd.io to only update the Docker engine.

For Docker-Compose, just follow again the installation instructions and override the already downloaded binary with the new version. Check out the release notes or the documentation to check for any breaking changes that might need a migration before.

Categories: