Share your love
Install Docker CE on Debian 12 Bookworm – Best Steps
In this guide, we want to teach you to Install and Use Docker CE on Debian 12 Bookworm. Docker is an open-source platform that can ease the creation, implementation, and performance processes with containers. First, let’s understand the Docker CE meaning and then start to install Docker CE on Debian 12 by using the guide steps from the Orcacore website.
Table of Contents
What is the difference between Docker and Docker CE?
Docker CE is a package provided by Docker. The package is available through a third-party package repository provided for major Linux distributions. Like the docker.io and docker packages, docker-ce is free and open source.
You can follow this guide to Install Docker CE on Debian 12 and start working with it.
How To Install Docker CE on Debian 12 Bookworm?
Before you start to Install Docker CE on Debian 12, you must have access to your server as a non-root user with sudo privileges. To do this, you can follow this guide on Initial Server Setup with Debian 12 Bookworm.
Then, follow the steps below to Install Docker CE on Debian 12.
Step 1 – Run System Update and Install Required Packages for Docker
First, you need to update and upgrade the APT packages by using the command below:
sudo apt update && sudo apt upgrade -y
Then, use the command below to install the required packages on Debian 12 for Docker:
sudo apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common -y
Step 2 – Add Docker’s official GPG key on Debian 12
At this point, you need to add the GPG key for the official Docker repository to your system by using the following commands:
# sudo install -m 0755 -d /etc/apt/keyrings
# curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# sudo chmod a+r /etc/apt/keyrings/docker.gpg
Step 3 – Set up Docker Repository on Debian 12
Here you need to add the Docker repository to the APT sources with the command below:
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Step 4 – How To Install Docker on Debian 12?
Finally, run the system update and use the following command to Install Docker CE on Debian 12:
# sudo apt update
# sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin -y
How To Check Docker Status?
Your Docker CE service must be enabled and activated during the installation on Debian 12. To verify it, you can run the command below:
sudo systemctl status docker
In your output you should see:
Output
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; preset: enabl>
Active: active (running) since Sat 2023-07-01 08:03:18 EDT; 12s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 2651 (dockerd)
Tasks: 9
Memory: 27.5M
CPU: 579ms
CGroup: /system.slice/docker.service
...
At this point, you have the docker command-line utility. In the rest of the article, we will show you how to use the docker command-line utility on Debian 12.
Step 5 – Run Docker Commands without sudo
The docker command can only be run by the root user or the user in the docker group. A Docker group is created in the installation process by default.
If you don’t want to use sudo for the docker command you need to add your user to the docker group with the following command:
sudo usermod -aG docker ${USER}
To apply this change, run the following command:
su - ${USER}
Here you will be asked to enter your username’s password to continue.
You can verify that your user added to the docker group with the following command:
id -nG
In the rest of the article, we run the docker commands as a user in the docker group. If you don’t want this remember to run commands with a user with sudo privileges.
After you have finished to Install Docker CE on Debian 12, Let’s see how the docker command works.
Step 6 – How To Use Docker Command Line Utility
The syntax of the docker command is like this form:
docker [option] [command] [arguments]
You can see all available subcommands of docker with the following command:
docker
In your output you will see:
Output
Common Commands:
run Create and run a new container from an image
exec Execute a command in a running container
ps List containers
build Build an image from a Dockerfile
pull Download an image from a registry
push Upload an image to a registry
images List images
login Log in to a registry
logout Log out from a registry
search Search Docker Hub for images
version Show the Docker version information
info Display system-wide information
Management Commands:
builder Manage builds
buildx* Docker Buildx (Docker Inc., v0.10.5)
compose* Docker Compose (Docker Inc., v2.18.1)
container Manage containers
context Manage contexts
image Manage images
...
How To Work with Docker Images on Debian12?
The Docker Image is a portable file that contains a set of instructions that specify which software components the Container should run and how to run it.
By default, Docker pulls these images from Docker Hub. Anyone can host their Docker images on Docker Hub, so most applications and Linux distributions you’ll need will have images hosted there.
You can check that you have access and download images from Docker Hub with the following command:
docker run hello-world
Your output should look like this:
Output
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete
Digest: sha256:a13ec89cdf897b3e551bd9f89d499db6ff3a7f44c5b9eb8bca40da20eb4ea1fa
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
Search for available Docker Images
Also, you can search for the available images on the Docker hub with the search subcommand.
For example, search for the Debian image with the following command:
docker search debian
In your output, you will see a listing of images that you have searched.
Output
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating sys… 16114 [OK]
debian Debian is a Linux distribution that's compos… 4706 [OK]
neurodebian NeuroDebian provides neuroscience research s… 100 [OK]
bitnami/debian-base-buildpack Debian base compilation image 2 [OK]
kasmweb/debian-bullseye-desktop Debian Bullseye desktop for Kasm Workspaces 0
mirantis/debian-build-ubuntu-xenial
...
Download a Docker Image
Here you can download the official Debian image with the following command:
docker pull debian
Your output should be similar to this:
Output
Using default tag: latest
latest: Pulling from library/debian
bba7bb10d5ba: Pull complete
Digest: sha256:d568e251e460295a8743e9d5ef7de673c5a8f9027db11f4e666e96fb5bed708e
Status: Downloaded newer image for debian:latest
docker.io/library/debian:latest
List Downloaded Docker Images
To see what images you have downloaded to your system run the following command:
docker images
In your output, you will see something similar to this:
Output
REPOSITORY TAG IMAGE ID CREATED SIZE
debian latest 49081a1edb0b 2 weeks ago 116MB
hello-world latest 9c7a54a9a43c 8 weeks ago 13.3kB
How to Run a Docker Container on Debian 12?
Containers can be the best replacement for virtual machines. Containers separate the executive environments and share the operation system’s core.
For example, run the container using the latest image of Debian. To do this run the following command:
docker run -it debian
Note: -it switches and gives you interactive shell access into the container.
You will see this form in your output:
Output
root@70c3b825b259:/#
Important note: Remember the container ID. Here the container ID is 70c3b825b259.
Now you can run any command in your container without sudo because you execute commands in the container as a root user.
Update the packages inside the container with the following command:
root@70c3b825b259:/# apt update
Now you can install any application that you want. For example, we install Apache:
root@70c3b825b259:/# apt install apache2
When the installation of Apache is finished, verify that Apache is installed with the following command:
root@70c3b825b259:/# apache2 -v
Output
Server version: Apache/2.4.57 (Debian)
Server built: 2023-04-13T03:26:51
Note: Any changes you make inside the container only apply to that container.
To exit the container type exit:
root@70c3b825b259:/# exit
List Active Docker Containers
At this step of Install Docker CE on Debian 12, you can view active containers by running the following command:
docker ps
Output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
You have started two containers in this article. But they are not activated.
To see all containers both active and inactive run the following command:
docker ps -a
Output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
70c3b825b259 debian "bash" 3 minutes ago Exited (130) About a minute ago boring_goodall
11b7515a7b34 hello-world "/hello" 10 minutes ago Exited (0) 10 minutes ago sweet_elbakyan
Also, you can see the latest container that you have created with the following command:
docker ps -l
Output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
70c3b825b259 debian "bash" 4 minutes ago Exited (130) About a minute ago boring_goodall
Manage Docker Containers
In this step of Install Docker CE on Debian 12, you can start and stop a container with the container ID or the container’s name.
Here we start the Debian-based container with the ID:
docker start 70c3b825b259
Now you can check the status to see if your container is active:
docker ps
Output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
70c3b825b259 debian "bash" 5 minutes ago Up 9 seconds boring_goodall
Here you can stop the container. Now we use the container’s name to stop it:
docker stop boring_goodall
Also, you can remove a container with the container ID or the container’s name. For example, remove the hello-world container with its name by the following command:
docker rm sweet_elbakyan
Containers can be turned into images that you can use to build new containers.
Let’s see how it works.
Step 7 – How To Make Docker Containers to Docker Images?
At this step of Install Docker CE on Debian 12, after installing Apache inside the Debian container on Debian 12, you now have a container running off an image, but the container is different from the image you used to create it. But you might want to use this Apache container again as the basis for new images later.
You can commit the changes to a new docker image with the following command:
docker commit -m "What you did to the image" -a "Author Name" container_id repository/new_image_name
For example:
docker commit -m "install Apache" -a "olivia" 70c3b825b259 olivia/debian-apache
Now your new image is saved on your system.
List the docker images with the following command:
docker images
In your output you will see the new image:
Output
REPOSITORY TAG IMAGE ID CREATED SIZE
olivia/debian-apache latest 118327ea7c75 10 seconds ago 252MB
debian latest 49081a1edb0b 2 weeks ago 116MB
hello-world latest 9c7a54a9a43c 8 weeks ago 13.3kB
Note: The size difference reflects the changes that were made.
At this point, you can share the new image with others so they can create containers from it.
Step 8 – How To Share Docker Images to a Docker Repository?
After you create a new image from an existing image on Debian 12 you can share it with others on Docker Hub or other Docker repositories that you have access to.
First, you need to create an account on Docker Hub.
Then log in to your Docker Hub to push your image with the following command:
docker login -u docker-registry-username
You will be asked to enter your Docker Hub password.
Note: If your Docker registry username is different from the local username you used to create the image, you will have to tag your image with your registry username.
For example:
docker tag olivia/debian-apache docker-registry-username/debian-apache
Then push your own image with the following command:
docker push docker-registry-username/docker-image-name
The process may take some time to complete as it uploads the images.
After pushing an image to a registry, it should be listed on your account’s dashboard.
Note: If a push attempt results in an error, Log in again and repeat the push attempt. Then verify that it exists on your Docker Hub repository page.
Conclusion
At This point, you have learned to Install Docker CE on Debian 12 Bookworm. Also, you have learned to work with Docker images, and Docker containers, manage containers, and how to make Docker containers into images and share them on a Docker repository.
Hope you enjoy this guide on Install Docker CE on Debian 12. You may be interested in these articles too:
Install Symfony PHP Framework on Debian 12