docker on debian

Docker is a containerization platform that allows you to quickly build, test and deploy applications as portable, self-sufficient containers that can virtually run everywhere.

Docker is de facto standard for container technology and it is an essential tool for DevOps engineers and their continuous integration and delivery pipeline.

In this tutorial, we will guide you through the process of installing Docker on a Debian 9 machine and explore the basic Docker concepts and commands.

Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

The following steps describe how to install the latest stable Docker version from the Docker’s repositories.

  1. Update the installed packages to the latest version
    sudo apt updatesudo apt upgrade
  2. Install the dependencies necessary to add a new repository over HTTPS:
    sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg2
  3. Import the repository’s GPG key using the following curl command:
    curl -fsSL | sudo apt-key add -

    Add the Docker APT repository to your system’s software repository list by typing:

    sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"

    $(lsb_release -cs) will return the name of the Debian distribution, in this case it will return stretch.

  4. Now that the Docker repository is enabled, update the apt package list and install the latest version of Docker CE (Community Edition) with:
    sudo apt updatesudo apt install docker-ce
  5. Once the installation is completed the Docker service will start automatically. You can verify it by typing:
    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 Fri 2018-07-27 17:02:07 UTC; 1min 14s ago
    Main PID: 16929 (dockerd)
    CGroup: /system.slice/docker.service
  6. At the time of writing, the current version of Docker available for Debian 9 is 18.06.0-ce. Check the Docker version with:
    docker -v
    Docker version 18.06.0-ce, build 0ffa825

By default, only a user with administrator privileges can execute Docker commands.

If you want to run Docker commands as a non-root user without prepending sudo you’ll need to add your user to the docker group which is created during the installation of the Docker CE package. You can do that by typing:

sudo usermod -aG docker $USER


Log out and log back in so that the group membership is refreshed.

To verify that you can run docker commands without prepending sudo run the following command which will download a test image, run it in a container, print a “Hello from Docker” message and exit:

docker container run hello-world

Now that we have Docker installed, let’s go over the basic syntax of the docker CLI:

docker [option] [subcommand] [arguments]


To list all available commands run docker with no parameters:



If you need more help on any [subcommand], you can use the --help switch as shown bellow:

docker [subcommand] --help

Leave a Reply

Your email address will not be published. Required fields are marked *