Docker is an open-source container runtime that allows you to build, run, and manage applications in isolated environments called containers.
Docker Engine was introduced in 2013 as an industry-standard tool to provide a universal packaging method. Today, developers adopt this tool to create applications and improve the cloud. The docker containers have their own system and a lock function that cannot interfere with the operation of the main server. This tutorial will show you how to install Docker on Debian 12.
- A Debian 12 VPS
- SSH access with sudo privileges or root access.
In addition, it is recommended to have at least 2GB of SWAP memory, even if you have enough available RAM.
Step 1. Update the System
First of all, we need to log in to our Debian 12 VPS through SSH:
ssh root@IP_Address -p Port_number
Replace “root” with a user that has sudo privileges or root if necessary. Additionally, replace “IP_Address” and “Port_Number” with your server’s respective IP address and SSH port number. Next, let’s make sure that we’re on Debian 12. You can do that like this:
# lsb_release -a
The command should return an output similar to this:
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Step 2. Install Docker
There are some methods to install Docker on Debian 12 system, depending on your needs:
Install Docker Engine from Docker’s Apt repository.
This is by far the best and most recommended way to install Docker because we can perform the update easily. Before installing Docker Engine for the first time on a new host machine, you need to configure the Docker Apt repository. Then you can install and update Docker from the repository.
Execute these commands to add and set up Docker’s Apt repository.
# apt update # apt install ca-certificates curl gnupg # install -m 0755 -d /etc/apt/keyrings # curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg # chmod a+r /etc/apt/keyrings/docker.gpg
Then, add Docker’s APT repository to the APT source.
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" | \ tee /etc/apt/sources.list.d/docker.list > /dev/null
Once added, update the package index files on the system.
# apt update
Finally, install the docker packages.
# apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
That’s it; docker has been installed on your Debian system. We can run this command below to verify the installation.
# docker version
It will show you an output like this:
Client: Docker Engine - Community Version: 24.0.6 API version: 1.43 Go version: go1.20.7 Git commit: ed223bc Built: Mon Sep 4 12:32:10 2023 OS/Arch: linux/amd64 Context: default Server: Docker Engine - Community Engine: Version: 24.0.6 API version: 1.43 (minimum version 1.12) Go version: go1.20.7 Git commit: 1a79695 Built: Mon Sep 4 12:32:10 2023 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.22 GitCommit: 8165feabfdfe38c65b599c4993d227328c231fca runc: Version: 1.1.8 GitCommit: v1.1.8-0-g82f18fe docker-init: Version: 0.19.0 GitCommit: de40ad0
Also, you can try running a simple docker image, and invoke the following command:
# docker run hello-world
The command above will download a test image and run it in a container. When the container runs, it prints a confirmation message and then exits.
If you run the command as a regular system user without sudo privileges, you might see an error message. So, if you want to run docker commands without sudo, you can add the user to the docker’s group by executing this command below.
# usermod -aG docker $USER # newgrp docker
Do not forget to replace $USER with your actual system user.
Install it and manage the upgrade manually.
This method allows us to install docker by downloading .deb packages and then simply installing the packages. To proceed with this installation method, follow these steps.
Navigate to the Docker download page.
Download the following deb files for the Docker Engine, CLI, containers, and Docker Compose packages:
containerd.io_<version>_<arch>.deb docker-ce_<version>_<arch>.deb docker-ce-cli_<version>_<arch>.deb docker-buildx-plugin_<version>_<arch>.deb docker-compose-plugin_<version>_<arch>.deb
For example, we will download these files.
Install the files by running this command:
dpkg -i ./containerd.io_<version>_<arch>.deb \ ./docker-ce_<version>_<arch>.deb \ ./docker-ce-cli_<version>_<arch>.deb \ ./docker-buildx-plugin_<version>_<arch>.deb \ ./docker-compose-plugin_<version>_<arch>.deb
Or, if you download the same files as mentioned in this article, run this command:
dpkg -i ./containerd.io_1.6.22-1_amd64.deb \ ./docker-ce_24.0.6-1~debian.12~bookworm_amd64.deb \ ./docker-ce-cli_24.0.6-1~debian.12~bookworm_amd64.deb \ ./docker-buildx-plugin_0.11.2-1~debian.12~bookworm_amd64.deb \ ./docker-compose-plugin_2.21.0-1~debian.12~bookworm_amd64.deb
The Docker daemon starts automatically upon installation.
Verify that the Docker Engine installation is successful by running the hello-world image:
# service docker start # docker run hello-world
Another method is to install docker using a script. But, this is recommended only for test and development environments. If you want to try this method, you can execute these commands.
# curl -fsSL https://get.docker.com -o get-docker.sh
# sh get-docker.sh
The script will install and start docker immediately.
Step 3. Docker Commands
After installing docker, you can create and run docker images. These are some examples of docker commands.
This command will help you search for an application that is available in docker.
Docker pull is used for taking the application from the official Docker Hub. For example, we can pull WordPress. docker pull wordpress
docker run command is used for creating a container from an image. As seen in the previous step, we ran the docker run hello-world command
For more docker commands, you can check it with docker –help command
root@host:~# docker help Usage: docker [OPTIONS] COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/root/.docker") -c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") --tlskey string Path to TLS key file (default "/root/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit
That’s it! You have successfully installed Docker on your Debian 12 system.
Now, it’s your opportunity to share:
Did you find any of the steps confusing, or do you think we left something out? We look forward to hearing your thoughts, so please leave a comment below.
Whether you have an active VPS with us or not, if you enjoyed this post, please share it with your friends on social networks or simply leave a comment in the comments section. Thanks.