Skip to main content
  1. Posts/
  2. Docker/

·413 words·2 mins·
Jaume Sabater
Author
Jaume Sabater
CTO and systems engineer
Table of Contents

Docker installation and first commands
#

We are going to introduce the Docker CLI (Command Line Interface) with a PostgreSQL database and an Apache HTTP server with PHP support on Debian/Ubuntu. We will download images and create containers from those images, and we will learn to work with volumes and networks.

The Docker CLI provides a wide range of commands to interact with Docker services, which we will group up into four categories:

  1. Image management, e.g., docker pull, docker images, docker rmi.
  2. Container management, e.g., docker run, docker ps, docker rm.
  3. Volume management, e.g., docker volume ls, docker volume create.
  4. Network management, e.g., docker network ls, docker network create.

Installation
#

Follow the installation instructions for your distribution. We will mostly be working with Debian or Debian-based distributions. Most commands in this section require root privileges, therefore we use sudo..

First of all, make sure that no conflicting packages from the distribution repositories are installed. The following command can help you with that:

sudo apt-get remove docker.io docker-doc docker-compose podman-docker containerd runc

Install the prerequisite packages:

sudo apt-get update
sudo apt-get install ca-certificates curl

Add Docker’s official GPG key to the keyring:

sudo install --mode=0755 --directory /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod 0644 /etc/apt/keyrings/docker.asc

Finally, add the repository:

ARCH=$(dpkg --print-architecture)
CODENAME=$(source /etc/os-release && echo "$VERSION_CODENAME")
sudo tee /etc/apt/sources.list.d/docker.sources > /dev/null << EOF
Types: deb
Components: main
Architectures: $ARCH
URIs: https://download.docker.com/linux/debian
Suites: $CODENAME
Signed-By: /etc/apt/keyrings/docker.asc
EOF

Install the latest version:

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

The Docker service starts automatically after installation. To verify that Docker is running, use:

systemctl status docker

Finally, in order to be able to use the docker command as a non-privileged user, you must add your user to the docker group:

sudo adduser <myusername> docker

You will need to log out and log back in for the changes to take effect.

First commands
#

The Docker CLI uses the docker command. As a first example, check the Docker version:

docker --version

Also make sure you have enough system resources before downloading images and running containers:

free -h
df -h

Because it is difficult to keep everything in mind, the Docker CLI provides a list of available commands, arguments and flags, with short explanations and usage, via inline help:

docker --help

Beyond getting the list of available commands, you usually will want to get help from a specific command:

docker pull --help
docker run --help
docker volume --help
docker network --help

Related