Docker
Getting started
Section titled “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
Section titled “References”Docker Desktop
Section titled “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
Section titled “Docker Engine”Pre-install
Section titled “Pre-install”-
Install required dependencies
Section titled “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 -
Install required keyrings
Section titled “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 -
Add Docker GPG key
Section titled “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 -
Change file permission
Section titled “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 -
Add docker repository to apt source
Section titled “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/nullTerminal window 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 -
Update apt package list
Section titled “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
Section titled “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.
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -yPost-install
Section titled “Post-install”-
Add user to docker group
Section titled “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 -
Modify user permissions
Section titled “Modify user permissions”Modify user permissions to ensure they have the necessary access rights to interact with Docker.
Terminal window sudo usermod -aG docker $USER -
Reboot the system
Section titled “Reboot the system”Finally, reboot your system to ensure all changes take effect.
Terminal window sudo reboot
Docker data on external HDD (optional)
Section titled “Docker data on external HDD (optional)”-
Stop docker
Section titled “Stop docker”Stop the Docker service.
Terminal window sudo systemctl stop docker -
Move docker data
Section titled “Move docker data”Move docker data to the new directory.
Terminal window sudo mv /var/lib/docker {{EXTERNAL_HDD_PATH_VAR}}/docker-data -
Open daemon.json
Section titled “Open daemon.json”Terminal window sudo nano /etc/docker/daemon.json -
Modify Docker daemon.json
Section titled “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"} -
Restart Docker
Section titled “Restart Docker”Restart the Docker service.
Terminal window sudo systemctl daemon-reload && sudo systemctl restart docker -
Verify change
Section titled “Verify change”Check if Docker is now using the new directory.
Terminal window # Docker Root Dir: {{EXTERNAL_HDD_PATH_VAR}}/docker-datadocker info | grep "Docker Root Dir"