Skip to content

Docker

Getting started

Installing Docker on a Debian-based Linux system is a straightforward process, but ensuring that all dependencies, keyrings and configurations are correctly set up is crucial for a smooth installation. This guide walks you through the steps needed to install Docker, add users to the Docker group and finalize the setup for managing containers on your Debian system. By the end of this guide, your system will be fully ready to run Docker containers efficiently and securely.

References


Docker Desktop

Docker Desktop is the recommended way to run Docker on macOS and Windows, as it provides an easy-to-use interface and built-in tools for managing containers.

For Linux, Docker Desktop is not required. Instead, you can install the Docker Engine (see below) directly, which provides all the necessary functionality without the additional overhead of Docker Desktop.


Docker Engine

Pre-install

  1. Install required dependencies

    Before installing Docker, ensure your system has all the necessary dependencies. This step installs packages that are essential for Docker to function properly on Debian Linux.

    Terminal window
    sudo apt install ca-certificates curl -y
  2. Install required keyrings

    Docker requires keyrings to authenticate the software packages during installation. This step ensures that your system has the appropriate keyrings installed to verify Docker’s official package sources.

    Terminal window
    sudo install -m 0755 -d /etc/apt/keyrings
  3. Add Docker GPG key

    Add the official Docker GPG key to your system’s keyring. This ensures that packages you download are verified as authentic and from the trusted Docker repositories.

    Terminal window
    sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
  4. Change file permission

    Modify the file permissions to ensure Docker’s configuration files and directories are properly accessible. This step is essential for maintaining system security and ensuring Docker operates smoothly.

    Terminal window
    sudo chmod a+r /etc/apt/keyrings/docker.asc
  5. Add docker repository to apt source

    Add Docker’s official repository to your APT sources. This will allow you to install Docker directly from Docker’s official repository, ensuring you get the latest version.

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

    Run an APT update to refresh your package database and include the new Docker repository. This ensures that your system recognizes Docker as an available package for installation.

    Terminal window
    sudo apt update

Install Docker

Install the Docker Engine on your system. This command downloads and installs the latest stable version of Docker, enabling you to start using Docker on your Debian system.

Terminal window
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

Post-install

  1. Add user to docker group

    Add your user to the docker group. This allows you to run Docker commands without needing sudo each time, streamlining the Docker management process.

    Terminal window
    sudo groupadd docker
  2. Modify user permissions

    Modify user permissions to ensure they have the necessary access rights to interact with Docker. This step ensures that the user has proper control over Docker without compromising system security.

    Terminal window
    sudo usermod -aG docker $USER
  3. Reboot the system

    Finally, reboot your system to ensure all changes take effect. This step ensures that your system is fully prepared to run Docker and any necessary services start properly on boot.

    Terminal window
    sudo reboot

Docker data on external HDD (optional)

  1. Stop docker

    Stop the Docker service.

    Terminal window
    sudo systemctl stop docker
  2. Move docker data

    Move docker data to the new directory.

    Terminal window
    sudo mv /var/lib/docker {{{EXTERNAL_HDD_PATH_VAR}}}/docker-data
  3. Open daemon.json

    Terminal window
    sudo nano /etc/docker/daemon.json
  4. Modify Docker daemon.json

    Modify the Docker daemon settings to use the new directory.

    /etc/docker/daemon.json
    {
    "data-root": "{{{EXTERNAL_HDD_PATH_VAR}}}/docker-data"
    }
  5. Restart Docker

    Restart the Docker service.

    Terminal window
    sudo systemctl daemon-reload && sudo systemctl restart docker
  6. Verify change

    Check if Docker is now using the new directory.

    Terminal window
    # Docker Root Dir: {{{EXTERNAL_HDD_PATH_VAR}}}/docker-data
    docker info | grep "Docker Root Dir"