In this tutorial, we will learn how to install and use Docker on a Debian 10 VPS.
Docker is a free and open-source tool that uses OS-level virtualization to deliver software in packages called containers. Docker is specially designed to make it easier to create, deploy and run applications by using containers. Docker containers are lightweight and very similar to Virtual Machine, using the host OS. Containers allow you to package up an application with all required libraries and other dependencies and ship it in one package.
Docker shares the same Linux kernel and other resources as the system that they’re running on, and only require the application along with its dependencies to be packaged. This will speed up your system performance and reduces the size of the application. Docker is free, so anyone can contribute to Docker and it being open-source allows anyone to extend it and meet their own needs. The main goal for the Docker is for developers to develop the applications easily, ship them into containers, and deploy it anywhere.
Table of Contents
Prerequisites:
- A VPS running Debian 10. For the purposes of this tutorial, we will use our SSD 2 Debian 10 VPS.
- Full SSH root access or a user with sudo privileges is also required.
Step 1: Log in via SSH and Update Packages
Log in to your Debian 10 VPS with SSH as the root user:
ssh root@IP_Address -p Port_number
Replace “root” with a user that has sudo privileges 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 10. You can do that like this:
# lsb_release -a
You should get this as the output:
Distributor ID: Debian Description: Debian GNU/Linux 10 (buster) Release: 10 Codename: buster
Then, run the following command to make sure that all installed packages on the server are updated to their latest available versions:
# apt update && apt upgrade
Step 2: Install Docker
Before starting, you will need to install some dependencies to allow your system to access the Docker repositories over HTTPS. You can install all of them with the following command:
sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common
Once all the required dependencies are installed, download and add the Docker’s GPG key with the following command:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
Next, add the Docker repository with the following command:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
Finally, update the repository and install the latest version of Docker with the following command:
sudo apt-get update sudo apt-get install docker-ce
Once the installation has been completed, check the status of Docker with the following command:
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 Wed 2019-09-18 07:14:31 EDT; 5min ago Docs: https://docs.docker.com Main PID: 17988 (dockerd) Tasks: 8 Memory: 91.0M CGroup: /system.slice/docker.service └─17988 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
You can also check the information about Docker with the following command:
sudo docker info
You should get the following output:
Client: Debug Mode: false Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 1 Server Version: 19.03.2 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f init version: fec3683 Security Options: apparmor seccomp Profile: default Kernel Version: 4.19.0-5-amd64 Operating System: Debian GNU/Linux 10 (buster) OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 987.5MiB Name: debian ID: DNIZ:KB6U:H3MN:RURG:G2DW:PGSF:2TIS:OPCF:RSNQ:RCGR:ZOCC:U6MF Docker Root Dir: /var/lib/docker Debug Mode: false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false
Step 2a: Install a Specific Version of Docker
In some cases, you need to install a specific version of Docker on your system. In this case, first list the available versions of Docker by running the following command:
sudo apt-cache madison docker-ce
You should see all the available version of Docker in the following output:
docker-ce | 5:19.03.2~3-0~debian-buster | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 5:19.03.1~3-0~debian-buster | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 5:19.03.0~3-0~debian-buster | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 5:18.09.9~3-0~debian-buster | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 5:18.09.8~3-0~debian-buster | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 5:18.09.7~3-0~debian-buster | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 5:18.09.6~3-0~debian-buster | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 5:18.09.5~3-0~debian-buster | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 5:18.09.4~3-0~debian-buster | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 5:18.09.3~3-0~debian-buster | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 5:18.09.2~3-0~debian-buster | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 5:18.09.1~3-0~debian-buster | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 5:18.09.0~3-0~debian-buster | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 18.06.3~ce~3-0~debian | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 18.06.2~ce~3-0~debian | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 18.06.1~ce~3-0~debian | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 18.06.0~ce~3-0~debian | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 18.03.1~ce-0~debian | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 18.03.0~ce-0~debian | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 17.12.1~ce-0~debian | https://download.docker.com/linux/debian buster/stable amd64 Packages docker-ce | 17.12.0~ce-0~debian | https://download.docker.com/linux/debian buster/stable amd64 Packages
Next, you can install your desired version of Docker with the following command:
sudo apt-get install docker-ce=
You can replace the with the version you want to install as shown in the above list.
For example:
sudo apt-get install docker-ce=18.03.1~ce-0~debian
Step 4: Run the Docker Command Without Sudo
By default, you will need to run Docker command with sudo privileges. If you want to run Docker command without specifying the sudo command, then you will need to add your username to the Docker group.
You can add your username to the Docker group with the following command:
sudo usermod -aG docker username
Now, log out from the server and log in again with your username to apply for the new group membership. Now, you can run any Docker command without specifying sudo with Docker.
Working with Docker
At this point, Docker is installed and running on your system. Now, we will learn how to pull an image and run the container with Docker.
First, search all the images available for the Debian operating system with the following command:
docker search debian
You should see all the images in the following output:
NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating sys… 9956 [OK] debian Debian is a Linux distribution that's compos… 3214 [OK] arm32v7/debian Debian is a Linux distribution that's compos… 60 itscaro/debian-ssh debian:jessie 25 [OK] arm64v8/debian Debian is a Linux distribution that's compos… 21 samueldebruyn/debian-git a minimal docker container with debian and g… 21 [OK] i386/debian Debian is a Linux distribution that's compos… 10 multiarch/debian-debootstrap multiarch ports of debian-debootstrap 9 eboraas/debian Debian base images, for all currently-availa… 8 [OK] vergissberlin/debian-development Docker debian image to use for development, … 6 [OK] debian/eol End of Life Debian versions (pointing at arc… 5 smartentry/debian debian with smartentry 4 [OK] ppc64le/debian Debian is a Linux distribution that's compos… 4 vicamo/debian Debian docker images for all versions/archit… 3 s390x/debian Debian is a Linux distribution that's compos… 2 arm32v5/debian Debian is a Linux distribution that's compos… 2 vpgrp/debian Docker images of Debian. 2 holgerimbery/debian debian multiarch docker base image 1 dockershelf/debian Repository for docker images of Debian. Test… 1 [OK] fleshgrinder/debian Debian base images for production and multis… 0 [OK] spritsail/debian-builder A Docker image based on debian:slim ideal fo… 0 [OK] casept/debian-amd64 A debian image built from scratch. Mostly fo… 0 amd64/debian Debian is a Linux distribution that's compos… 0 jdub/debian-sources-resource Concourse CI resource to check for updated D… 0 [OK] 1and1internet/debian-9-nginx-php-7.2-wordpress-4 debian-9-nginx-php-7.2-wordpress-4 0
Now, download the latest version of the Debian image from the above list with the following command:
docker pull debian
Once downloaded, you should get the following output:
Using default tag: latest latest: Pulling from library/debian 4a56a430b2ba: Pull complete Digest: sha256:e25b64a9cf82c72080074d6b1bba7329cdd752d51574971fd37731ed164f3345 Status: Downloaded newer image for debian:latest docker.io/library/debian:latest
You can also list the downloaded image with the following command:
docker images
You should get the following output:
REPOSITORY TAG IMAGE ID CREATED SIZE debian latest c2c03a296d23 6 days ago 114MB
Now, run a container using the latest Debian image with the following command:
docker run -it debian
You should get the shell interface of a Debian container:
root@114ef7960999:/#
You can exit from the container with the following command:
root@114ef7960999:/#exit
You can also list your active or inactive container with the following command:
docker ps -a
Output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 114ef7960999 debian "bash" About a minute ago Exited (0) 16 seconds ago sharp_booth
You can also start the Debian container by specifying Container ID (114ef7960999) as shown below:
docker container start 114ef7960999
Now, attach the shell interface of a Debian container with the following command:
docker attach 114ef7960999 Output: root@114ef7960999:/#
Delete a Docker Container and Image
You can easily remove unused containers and images that consume significant disk space.
To remove the Docker container, first list all the container with the following command:
docker container ls -a
You should see the following output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 114ef7960999 debian "bash" 19 hours ago Exited (0) 19 hours ago sharp_booth
Next, if your container is running, you will need to stop the container before removing it.
You can stop the running container with the following command:
docker container stop 114ef7960999
Next, remove the container with the following command:
docker container rm 114ef7960999
You can also remove all stopped containers by just running the following command:
docker container prune
You should see the following warning message:
WARNING! This will remove all stopped containers. Are you sure you want to continue? [y/N] y
Type y and hit Enter to continue:
Deleted Containers: 114ef7960999f41bb9c4bba2cf5c28e425a00175ab20ed739213f16961b3897e Total reclaimed space: 35B
To remove the Docker image, you will need to find the ID of the image you want to remove.
You can find the image ID with the following command:
docker image ls
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE debian latest c2c03a296d23 7 days ago 114MB
Now, remove the image with the following command:
docker image rm c2c03a296d23
You should get the following output:
Untagged: debian:latest Untagged: debian@sha256:e25b64a9cf82c72080074d6b1bba7329cdd752d51574971fd37731ed164f3345 Deleted: sha256:c2c03a296d2329a4f3ab72a7bf38b78a8a80108204d326b0139d6af700e152d1 Deleted: sha256:78c1b9419976227e05be9d243b7fa583bea44a5258e52018b2af4cdfe23d148d
Note: To remove the image, you will have to remove the container first.
You can also remove all unused images at a time by just running the following command:
docker image prune -a
In the above tutorial, we have learned how to install Docker on a Debian 10 VPS. We have also learned how to pull an image, run container, start and stop the container.
Of course, you don’t have to know how to install Docker on Debian 10 if you have a Managed Debian 10 VPS with us. You can simply ask our administrators to install Docker on Debian 10 for you. They’re available 24/7 and will be able to help you with the installation of Docker on Debian 10.
PS. If you enjoy reading this blog post on how to install Docker on Debian 10, feel free to share it on social networks using the shortcuts below, or simply leave a comment.