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.
Install Docker on Debian
The following steps describe how to install the latest stable Docker version from the Docker’s repositories.
- Update the installed packages to the latest version
sudo apt updatesudo apt upgrade
- Install the dependencies necessary to add a new repository over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg2
- Import the repository’s GPG key using the following curl command:
curl -fsSL https://download.docker.com/linux/debian/gpg | 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] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
$(lsb_release -cs)will return the name of the Debian distribution, in this case it will return
- Now that the Docker repository is enabled, update the
aptpackage list and install the latest version of Docker CE (Community Edition) with:
sudo apt updatesudo apt install docker-ce
- 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 Docs: https://docs.docker.com Main PID: 16929 (dockerd) CGroup: /system.slice/docker.service
- 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 version 18.06.0-ce, build 0ffa825
Executing the Docker Command Without Sudo
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
Docker command line interface
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