Install specific versions of Docker Engine and Docker Compose

Install specific versions of Docker Engine and Docker Compose by using Docker's official repository for the engine and downloading the standalone binary for Compose.

Here’s the step-by-step process to install Docker Engine v27.5.1 and Docker Compose v2.18.1 on Ubuntu 22.04.

1. Prepare Your System

First, uninstall any old or conflicting Docker packages to ensure a clean installation.

sudo apt-get remove docker docker-engine docker.io containerd runc

Next, update your package list and install the necessary prerequisites to use Docker's HTTPS repository.

sudo apt-get update
sudo apt-get install ca-certificates curl

2. Set Up Docker's APT Repository

Add Docker’s official GPG key to verify the package integrity.

sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

Now, add the Docker repository to your APT sources.

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

3. Install Docker Engine v27.5.1

Update your package list again to include the packages from the newly added Docker repo.

sudo apt-get update

To install a specific version, you first need the exact version string. You can list available versions with this command:

apt-cache madison docker-ce

Once you find the version string for 27.5.1 (it will look something like 5:27.5.1-1~ubuntu.22.04~jammy), use it in the installation command.

# Replace <VERSION_STRING> with the actual string from the previous command
VERSION_STRING="5:27.5.1-1~ubuntu.22.04~jammy"

sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin

Note: If version 27.5.1 is not yet available in the repository, this command will fail. You must choose an available version from the madison command output.

4. Install Docker Compose v2.18.1

Download the specific version of the Docker Compose binary directly from the official GitHub repository.

sudo curl -L "https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Apply executable permissions to the binary.

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

To run Docker commands without sudo, add your user to the docker group.

sudo usermod -aG docker $USER

For this change to take effect, you must log out and log back in or run newgrp docker.

6. Verify the Installation

Finally, check the versions to confirm that the correct versions were installed.

Check the Docker Engine version:

docker --version

Expected Output: Docker version 27.5.1, build ...

Check the Docker Compose version:

docker-compose --version

Expected Output: Docker Compose version v2.18.1

Run the hello-world image to ensure Docker is working correctly.

docker run hello-world

If the installation was successful, you'll see a message confirming that your installation appears to be working correctly.