Installing Docker on Debian can significantly enhance your development and deployment workflows. Docker allows you to package applications and their dependencies into containers, ensuring consistency across different environments. This guide will walk you through the process of installing Docker on a Debian system, from updating your package list to verifying the installation.
Prerequisites
Before you begin, ensure that your Debian system meets the following prerequisites:
- A Debian-based system (e.g., Debian 10, Debian 11).
- Root or sudo privileges.
- A stable internet connection.
Update Your Package List
The first step in installing Docker on Debian is to update your package list. This ensures that you have the latest information on the newest versions of packages and their dependencies.
Open your terminal and run the following command:
sudo apt-get update
This command fetches the latest package lists from the repositories, ensuring that you have the most up-to-date information.
Install Required Packages
Next, you need to install a few prerequisite packages that allow apt to use repositories over HTTPS:
sudo apt-get install
apt-transport-https
ca-certificates
curl
gnupg
lsb-release
These packages are essential for adding the Docker repository and verifying the packages you download.
Add Docker’s Official GPG Key
To ensure the integrity of the packages you download, you need to add Docker’s official GPG key. This key is used to verify the authenticity of the Docker packages.
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg –dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
This command downloads the GPG key and saves it to the specified location.
Add the Docker Repository
Now, add the Docker repository to your system’s sources list. This allows you to install Docker directly from Docker’s official repository.
echo
“deb [arch=(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian
(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
This command adds the Docker repository to your sources list, ensuring that you can install Docker from the official repository.
Update the Package List Again
After adding the Docker repository, update your package list again to include the new repository:
sudo apt-get update
This command ensures that your system is aware of the Docker packages available in the newly added repository.
Install Docker Engine
Now that your package list is updated, you can install the Docker Engine. This is the core component of Docker that allows you to run containers.
sudo apt-get install docker-ce docker-ce-cli containerd.io
This command installs Docker Engine, the Docker CLI, and containerd, which is a core container runtime.
Verify the Installation
To verify that Docker has been installed correctly, run the following command:
sudo docker –version
This command should display the installed version of Docker, confirming that the installation was successful.
Manage Docker as a Non-Root User
By default, Docker commands must be run with root privileges. To allow a non-root user to run Docker commands, you need to add the user to the docker group.
First, create the docker group if it doesn’t already exist:
sudo groupadd docker
Next, add your user to the docker group:
sudo usermod -aG docker USER</code></pre>
<p>To apply the new group membership, log out and log back in, or restart your system.</p>
<p>You can verify that your user has been added to the <code>docker</code> group by running:</p>
<pre><code>groups USER
This command should list the groups that your user belongs to, including docker.
💡 Note: Adding a user to the docker group grants the user root-level access to the host. Be cautious when adding users to this group.
Enable and Start Docker Service
To ensure that Docker starts automatically on boot, enable the Docker service:
sudo systemctl enable docker
To start the Docker service immediately, run:
sudo systemctl start docker
You can check the status of the Docker service with:
sudo systemctl status docker
This command should show that the Docker service is active and running.
Run a Test Container
To confirm that Docker is working correctly, run a test container. The hello-world image is a simple container that prints a welcome message.
sudo docker run hello-world
If everything is set up correctly, you should see a message indicating that Docker is installed and running.
Uninstall Docker
If you need to uninstall Docker for any reason, you can do so by removing the Docker packages and any associated data.
First, stop and disable the Docker service:
sudo systemctl stop docker
sudo systemctl disable docker
Next, remove the Docker packages:
sudo apt-get purge -y docker-ce docker-ce-cli containerd.io
Finally, remove any remaining Docker data:
sudo rm -rf /var/lib/docker
sudo rm -rf /etc/docker
sudo rm -rf /var/run/docker
sudo rm -rf /usr/local/bin/docker-compose
This will completely remove Docker from your system.
💡 Note: Uninstalling Docker will remove all containers, images, volumes, and networks. Make sure to back up any important data before proceeding.
Docker Compose Installation
Docker Compose is a tool for defining and running multi-container Docker applications. While Docker Compose is not included in the Docker Engine installation, you can install it separately.
First, download the latest version of Docker Compose:
sudo curl -L “https://github.com/docker/compose/releases/download/$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep -oP ‘“tag_name”: “K(.*)(?=”)’)/docker-compose-(uname -s)-(uname -m)” -o /usr/local/bin/docker-compose
Next, apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose
Finally, verify the installation by checking the version:
docker-compose –version
This command should display the installed version of Docker Compose, confirming that the installation was successful.
Docker Compose File Example
Here is an example of a Docker Compose file (docker-compose.yml) that defines a simple application with a web service and a database:
| Service | Image | Ports | Environment |
|---|---|---|---|
| web | nginx | 80:80 | N/A |
| db | mysql | 3306:3306 | MYSQL_ROOT_PASSWORD=example |
To run this example, save the above configuration to a file named docker-compose.yml and run:
docker-compose up
This command will start the services defined in the Docker Compose file.
💡 Note: Docker Compose files can be customized to fit the specific needs of your application. Refer to the official Docker Compose documentation for more details.
Installing Docker on Debian is a straightforward process that involves updating your package list, installing prerequisite packages, adding the Docker repository, and installing Docker Engine. By following these steps, you can have Docker up and running on your Debian system in no time. This powerful tool will enable you to create, deploy, and manage containers efficiently, streamlining your development and deployment workflows.
Related Terms:
- docker install on debian 13
- debian docker download
- docker cli install debian
- debian 10 install docker
- installing docker debian 13
- install docker engine debian