Docker is an open-source platform that enables OS-level virtualization for developing, shipping, and running applications. It delivers applications in standardized units called containers, each isolated with its own libraries and configuration files but capable of communicating via well-defined network channels.
Docker has become a cornerstone in software development and DevOps, with millions of developers relying on it daily to build, share, and run applications throughout the lifecycle—from development to testing and production. Docker adds flexibility and portability by making applications runnable on any operating system without altering the application structure.
This guide will walk you through installing Docker Engine on Debian 12, managing Docker services using systemctl, and performing basic operations with Docker to manage images, containers, and volumes.
Prerequisites
Before proceeding, ensure you have:
- A Debian 12 machine (desktop or server)
- A non-root user with sudo privileges
Installing Docker Engine
To install the latest Docker Engine, use the official Docker repository. First, update the Debian package information and install some essential packages like ca-certificates, curl, and gnupg. Confirm when prompted by typing ‘y’ and pressing ENTER.
sudo apt update sudo apt install ca-certificates curl gnupg
Next, set up the GPG key for the Docker repository, which will be stored at /etc/apt/keyrings/ directory.
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
Execute the following commands to add the Docker repository:
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
Refresh the repository and install Docker Engine along with containerd and additional plugins:
sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Type y when prompted and press ENTER.
To verify installation, check Docker’s version:
docker version
Managing Docker Service
Docker Engine requires containerd as its default container engine. Both services should be running. Manage Docker services with systemctl:
Check if services are enabled:
sudo systemctl is-enabled docker sudo systemctl is-enabled containerd
Check service status:
sudo systemctl status docker sudo systemctl status containerd
Start Docker services if needed:
sudo systemctl start docker sudo systemctl start containerd
Stop the services if required:
sudo systemctl stop docker sudo systemctl stop containerd
Restart services to apply configuration changes:
sudo systemctl restart docker sudo systemctl restart containerd
Configuring Docker for Non-root Users
To allow non-root users to run Docker containers, add them to the Docker group. Use the following commands:
sudo usermod -aG docker username su - username
Run the hello-world container to test:
docker run hello-world
Check all containers:
docker ps -a
Running and Managing Containers with Docker
With Docker Engine running, you can now manage containers. Learn the basics of:
- Managing images
- Creating and managing containers
- Checking container logs
- Managing Docker volumes
Managing Docker Images
Docker images package applications and dependencies for easy distribution via Docker Hub, the default image registry.
To download an image:
docker pull nginx
Specify a version:
docker pull nginx:alpine
List available images:
docker images
Remove an image:
docker rmi imagename
Managing Containers
Containers are instances of Docker images. You can configure containers to persist data and expose network ports.
To run a container:
docker run -it -d -p 8080:80 --name web nginx:alpine
Check running containers:
docker ps docker ps -a
Stop a container:
docker container stop web docker ps -a
Start a container:
docker container start web docker ps
Remove a container:
docker container rm optimistic_edison docker container rm optimistic_edison -f
Checking Container Logs
Logs are crucial for debugging. View container logs with:
docker logs web
Display the last few log lines:
docker logs --tail 15 web
Managing Docker Volume
Docker volumes provide persistent storage independent of container lifecycles.
Create a volume:
docker volume create myvol
List volumes:
docker volume ls
Inspect a volume:
docker volume inspect myvol
Use a volume in a container:
docker run -d \ -p 8081:80 \ --name web2 \ --mount source=myvol,target=/app \ nginx:alpine
Remove a volume:
docker rm web2 -f docker volume rm myvol
Conclusion
Congratulations! You’ve installed Docker Engine on Debian 12 and learned to manage services, images, containers, and volumes. To further explore, start building Docker images for your applications using Dockerfiles.
FAQ
- What is Docker? Docker is a platform that uses OS-level virtualization for developing, shipping, and running applications.
- Is Docker free to use? Yes, Docker is open-source and free to use, but there are enterprise options for additional features.
- Can Docker run on any operating system? Docker can run on most operating systems, including Linux, Windows, and macOS, but the installation process might differ.
- What are Docker containers? Containers are isolated packages that contain an application and its dependencies, ensuring consistency across environments.