How to Uninstall Docker (Snap Version) and Install Docker with Docker Compose on Ubuntu or Debian

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.

This sometimes fixes: Error response from daemon: invalid mount config for type “bind”: bind source path does not exist

What You’ll Need

  • A system running Ubuntu or Debian.
  • Terminal access with root or sudo privileges.

Steps

1. Checking and Uninstalling Docker (Snap Version)

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.

2. Installing Prerequisites

Before installing Docker, the script updates the package database and installs some required packages like apt-transport-https, ca-certificates, curl, gnupg, and lsb-release. These packages allow your system to access HTTPS repositories securely and verify their authenticity.

3. Setting Up Docker Repository

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.

4. Installing Docker Engine

With the repository set up, the script proceeds to install the Docker Engine, which includes the Docker CLI and the containerd.io container runtime.

5. Verifying Docker Installation

After installation, the script runs a simple hello-world Docker container to verify that Docker is installed and functioning correctly.

6. Optional: Installing Docker Compose

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.

The Script

Conclusion

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.