How to Install Docker on Debian 10
Choose a different version or distribution
Introduction
Before we begin talking on How to install docker on Debian 10. Let’s briefly understand - What is Docker?
Docker is an open-source platform that allows developers to automate the deployment and management of applications within lightweight, isolated containers.
Installing Docker on Debian 10 allows you to utilize containerization technology for managing and deploying applications.
This tutorial will walk you through the steps required to install Docker on Debian 10. By the end of the installation process, you will have Docker installed and be ready to start using containers to enhance your development and deployment workflows.
Advantages of Installing Docker on Debian 10
- Easy Installation & Setup: Docker can be installed on Debian 10 with minimal effort, thanks to the availability of Docker packages and straightforward setup process.
- Containerization: Docker enables isolating applications and their dependencies within containers, ensuring consistency and portability across different environments.
- Resource Efficiency: Docker containers are lightweight, making efficient use of system resources and allowing for the deployment of multiple applications on a single host.
- Rapid Deployment: Docker's ease of use and fast deployment process enable quick scaling and rolling out application updates without downtime, leading to improved productivity.
- Vast Ecosystem: Docker has a vast ecosystem that includes pre-built images, community support, and integration with popular tools, making it easier to work with and extend Docker functionalities.
Install Docker on Debian
To install the most recent stable version of Docker from the Docker repositories, follow these instructions.
01. Install the required packages to add a new repository over HTTPS:
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg2
02. Use the following curl
command to import the repository's GPG key:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
The command will return OK
if it is successful.
03. The stable Docker APT repository should be added to your system's list of software repositories:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
$(lsb release -cs)
returns the Debian distribution name. It is buster
in this case.
04. Install the most recent version of Docker CE (Community Edition) and update the apt
package list:
sudo apt update
sudo apt install docker-ce
05. The Docker service will start automatically after the installation is complete. To check, type in:
sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-07-30 20:52:00 GMT; 1min 11s ago
Docs: https://docs.docker.com
...
06. The most recent stable version of Docker is 19.03.1
as of this writing:
docker -v
Output
Docker version 19.03.1, build 74b1e89
Executing the Docker Command Without Sudo
By default, only root and users with sudo privileges can run Docker commands.
You must add your user to the docker group that is generated during the installation of the Docker CE package if you wish to run Docker commands without prepending sudo. You can do that by typing:
sudo usermod -aG docker $USER
Your username is stored in the environment variable $USER
.
Log out and back in again to refresh the group membership.
Once finished, type the following to confirm that you can run docker
commands without sudo
:
docker container run hello-world
The command will download a test image, execute it within a container, print a message saying "Hello from Docker," and then exit. The output should seem as follows:
Using Docker
Now that you have Docker installed on your Debian 10 system, let us review the fundamental ideas and commands of docker.
Docker Images
A Docker image consists of a number of filesystem levels that correspond to the instructions in the Dockerfile that make up an executable software application. An image is an immutable binary file that contains the application together with any additional dependencies, including any libraries, binaries, or instructions required for the application to function.
The majority of Docker images are accessible through Docker Hub. It is a cloud-based registry service that is used, among other features, to store Docker images in either a public or private repository.
Use the docker search
command to look for an image in the Docker Hub registry. For example, to find a Debian image, you would type:
docker search debian
Docker Containers
A container is an instance of an image. For a single application, process, or service, a container represents the runtime.
Although it may not be the best analogy, if you are a programmer, you may consider a Docker image to be a class and a Docker container to be an instance of that class.
Use the docker container
command to manage, start, stop, and remove containers. The following command, for instance, will launch a Docker container based on the Debian image. If you do not have the image locally, it will be downloaded first:
docker container run debian
Due to the lack of a long-running process and the absence of any further commands, the Debian container will shut down soon after starting. The container started up, executed a blank command, and then exited.
You can interact with the container using the command line by using the switch -it
. To start an interactive container type, do the following:
docker container run -it debian /bin/bash
Output
root@ee86c8c81b3b:/#
As you can see from the output above, the command prompt changes once the container is started, indicating that you are now operating from inside the container.
Use the following command to list all running Docker containers:
docker container ls
The output will be blank if no containers are currently running.
Pass it the -a
switch to display all containers:
docker container ls -a
Simply copy the container ID (or IDs) and paste them after the container rm
command to delete one or more containers:
docker container rm c55680af670c
FAQs to Install Docker on Debian 10
How do I update my Debian 10 system before installing Docker?
You can update your Debian 10 system by running the command sudo apt update
followed by sudo apt upgrade
.
How do I install Docker using the official installation script on Debian 10?
You can run the command curl -fsSL https://get.docker.com -o get-docker.sh
followed by sudo sh get-docker.sh
to install Docker using the official script.
Can I verify if Docker is installed correctly on Debian 10?
After installation, you can run docker version
to verify the Docker version and ensure it is installed correctly.
How can I run Docker without using sudo
every time on Debian 10?
To run Docker commands without using sudo
, add your user to the docker
group, as described in the previous answer.
How can I install Docker Compose on Debian 10?
You can install Docker Compose on Debian 10 by following the official Docker Compose installation instructions.
Are there any prerequisite packages I need to install before Docker on Debian 10?
The official Docker installation script will automatically install any necessary dependencies for Docker to function correctly.
What are the benefits of using Docker on Debian 10?
Docker allows for easy application deployment, scalability, isolation, version control, fast testing, and compatibility across different environments.
Conclusion
By following this tutorial, you can have Docker up and running on your Debian 10 system. This will allow you to leverage the power of containerization for running and managing applications in isolated environments, enhancing flexibility and scalability in your software development and deployment process.
If you have any suggestions or queries, kindly leave them in the comments section.