Docker – Setup on Linux


In my opinion, it is the easiest to develop modern applications using Docker. Docker is a tool for creating, deploying, and running applications in so-called “containers”. In this way, you can easily move the application from one device to another (e.g. to the cloud), in case you need this in the future. By approaching things this way, you learn important foundations for modern application architectures, e.g. microservices and distributed systems. Furthermore, you can later orchestrate your applications using Kubernetes or cloud providers such as Amazon AWS, Microsoft Azure or Google Cloud.

Step 1: Prepare the package manager

Here, I give you the commands necessary to get Docker up and running on your Debian system. For more details, you can also check out the Docker Documentation.

As always, we first bring our sources up-to-date:

sudo apt update && sudo apt upgrade

Next, we install some packages:

sudo apt install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

Then, we add the Docker GPG key:

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

Step 2: Add the repository

Since we want a stable environment, we add the stable repository. We do this by adding a PPA source to apt (= Personal Package Archive). This means, we just add a non-default source from which we can then install packages.

Important: Depending on your CPU architecture, you need to execute the command appropriate for your architecture. This also applies for ARM CPUs with hardware floating point support (armv7+). This means, if you are installing Docker on an ARM device such as Raspberry Pi or Banana Pi, use arch=armhf, and for others user arch=arm64.

You can find out your architecture by executing the following command:

dpkg --print-architecture

Command for amd64 or x86_64:

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/debian \
   $(lsb_release -cs) stable"

Command for armhf

sudo add-apt-repository \
   "deb [arch=armhf] https://download.docker.com/linux/debian \
   $(lsb_release -cs) stable"

Command for arm64

sudo add-apt-repository \
   "deb [arch=arm64] https://download.docker.com/linux/debian \
   $(lsb_release -cs) stable"

Step 2: Install Docker Engine

Again, we update the sources, now that we have added the repository:

sudo apt update

Finally, we install the Docker Engine:

sudo apt install docker-ce docker-ce-cli containerd.io

We can test that Docker is installed by running:

sudo docker run hello-world

Step 3: Add a new docker group

To avoid that we have to execute every docker command as sudo, we add a new group called docker to our system. We will then add the system users to the group, that should be able to run Docker commands. Important: This gives the user privileges that are the same as those of the root user! More details can be found on the Docker – Linux postinstall page.

sudo groupadd docker
sudo usermod -aG docker $USER

Apply the changes:

newgrp docker 

Test that we can run Docker commands without sudo:

docker run hello-world

Leave a Reply