Starting Docker on Arch Linux

A simple guide to installing, configuring, and using Docker.

Fundamental Concepts

What is Docker?

Docker lets you package and run applications inside lightweight, isolated containers. Containers share the host's Linux kernel, making them generally faster and lighter than virtual machines.

Key Components

  • Docker Engine: Runs and manages containers.
  • Docker CLI: The docker command.
  • Images: Templates used to create containers.
  • Containers: Running instances of images.
  • Registry: Stores and distributes images.
  • Compose: Manages multi-container applications.

Installation

Update Your System

sudo pacman -Syu

Install Docker

Docker is available directly from the official Arch repositories.

sudo pacman -S docker

Install Docker Compose

sudo pacman -S docker-compose
docker compose version

Start Docker

sudo systemctl enable --now docker

Verify the Installation

systemctl is-active docker
docker version
sudo docker run hello-world

Use Docker Without sudo

sudo usermod -aG docker "$USER"

Log out and back in before using Docker without sudo.

Security: Membership in the docker group effectively gives root-level control over the host.

Using Docker

Run a Container

docker run -d --name web -p 8080:80 nginx

This runs Nginx in the background and maps port 8080 on the host to port 80.

List Containers

docker ps
docker ps -a

Stop and Remove Containers

docker stop <container>
docker rm <container>
docker rm -f <container>

Manage Images

docker images
docker pull nginx
docker rmi <image>

Clean Up

docker system df
docker system prune

Be careful with cleanup commands because unused resources may still be needed.

Docker Compose

Compose is useful for applications that require multiple containers, such as a web server and database.

Example compose.yaml

services:
  web:
    image: nginx:latest
    ports:
      - "8080:80"

Compose Commands

docker compose up -d
docker compose ps
docker compose logs
docker compose down

Modern Compose files do not require a top-level version field.

Best Practices

Images

  • Use official or trusted images.
  • Pin versions when reproducibility matters.
  • Keep images small.
  • Update images regularly.

Security

  • Avoid --privileged unless necessary.
  • Don't expose unnecessary ports.
  • Avoid unnecessary host mounts.
  • Never put secrets inside Dockerfiles or images.
  • Keep Docker and the host updated.

Resource Limits

Containers share the host's CPU and memory. Limits can be applied when needed:

docker run -d --memory=512m nginx
docker run -d --cpus=1 nginx

References