Post

Install & configure Docker

Install & configure Docker

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings. Definition refers to: https://www.docker.com/resources/what-container/

Installation on Debian

Setup Docker repository:

1
2
3
4
5
6
7
8
9
10
11
12
13
# Add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update

Install Docker:

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

Installation on Arch Linux

Install Docker:

1
sudo pacman -S docker docker-compose

I suggest you to install also the docker-compose plugin, but that is optional.

Post-installation steps

Autostart the daemon:

1
2
sudo systemctl enable docker.service --now
sudo systemctl enable containerd.service --now

Add user to docker group:

1
sudo usermod -aG docker $USER

Hint: You have to log out and login again to have changes take affect. If you don’t want to do this then type newgrp docker.

Usage

1
docker [ start | stop ] image
1
docker run options image commands

An example and possible options can be found here: https://phoenixnap.com/kb/docker-run-command-with-examples

Showing a little help on every sub-command:

1
docker [ system | network | container | ... ] option --help

Troubleshooting

See logs of an container:

1
docker logs container-name

Get inside a container:

1
docker exec -it container-name /bin/bash

If Bash isn’t working then try /bin/sh.

Cleaning

Clean all at once:

1
docker system prune -f -a
parameterdescription
pruneRemove unused data. Also works with network prune, volume prune, image prune and so on.
-fForce
-aAll

Compose Skel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
services:
  service-name-one:
    image: developer/imagename:tag
    container_name: container-name
    restart: unless-stopped
    environment:
      - TZ=Europe/Amsterdam
      - PUID=1000
      - PGID=1000
    volumes:
      - ./folder-outside-of-container:/folder-inside-the-container
      - docker-volume:/docker-volume-inside-the-container
    ports:
      - 1337:8080 # outside:inside
    depends_on:
      - service-name-two #optional
  service-name-two:
    image: developer/imagename:tag
    container_name: container-name
    restart: unless-stopped

To start / stop docker compose files you have to create a directory. Create the compose.yml inside and then run:

1
docker compose [up|down] (--force-recreate)

Use --force-recreate to reload the docker compose YAML-file and update the image at once.

This post is licensed under CC BY 4.0 by the author.