In this tutorial, we’ll walk through the process of uninstalling Docker if it was installed using Snap, and then install Docker and Docker Compose using the official Docker repositories on Ubuntu or Debian systems.
- A system running Ubuntu or Debian.
- Terminal access with root or sudo privileges.
If Docker was installed via Snap (a package management system and software deployment tool), our script will first check for its presence. If found, it prompts the user whether to uninstall it. This step ensures that there are no conflicts between the Snap-installed Docker and the version we’re about to install.
Before installing Docker, the script updates the package database and installs some required packages like
lsb-release. These packages allow your system to access HTTPS repositories securely and verify their authenticity.
To ensure we get the latest version of Docker, the script adds Docker’s official GPG key and sets up the stable repository for Docker. This process involves detecting your Linux distribution and its version to configure the repository accordingly.
With the repository set up, the script proceeds to install the Docker Engine, which includes the Docker CLI and the
containerd.io container runtime.
After installation, the script runs a simple
hello-world Docker container to verify that Docker is installed and functioning correctly.
Docker Compose is a tool for defining and running multi-container Docker applications. The script prompts the user whether they wish to install Docker Compose. If the user agrees, it fetches the Docker Compose binary from Docker’s GitHub repository and installs it.
This script automates the process of transitioning from a Snap-installed Docker to a version maintained in Docker’s official repositories. It also provides the optional installation of Docker Compose for managing complex Docker applications. This method ensures that you’re using the most up-to-date and feature-rich versions of Docker.