Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 23Containers · Docker

How to install Docker on Linux

You need Docker on a build server, a small app server, or your lab VM. Install it from Docker's own repository — not the old docker.io package and not the curl | sh script on production. This how-to gives the short install for RHEL-family and Ubuntu, the first test, the safe way to use it without sudo, and the three settings to make on day one (log rotation, data folder, start at boot).

  • 5 Lessen
  • 10 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

23.1

The quick answer

RHEL 9/10:

dnf -y install dnf-plugins-core
dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable --now docker
docker run --rm hello-world

Ubuntu: add the key and the repository (step 3), then apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin.

23.2

Step by step

  1. Remove conflicting packages (RHEL has Podman and runc; Ubuntu may have docker.io):
dnf -y remove docker docker-client docker-common podman runc
apt-get remove -y docker.io docker-compose podman-docker containerd runc
  1. RHEL, Rocky, Alma: add the repo and install (step in the quick answer). Rocky and Alma use https://download.docker.com/linux/centos/docker-ce.repo. When dnf asks about the GPG key, check the fingerprint 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35.
  2. Ubuntu and Debian:
apt-get update
apt-get install -y ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" > /etc/apt/sources.list.d/docker.list
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  1. Day-one settings — log rotation (container logs can fill the disk) and, if needed, another data folder:
/etc/docker/daemon.json
{
  "log-driver": "json-file",
  "log-opts": { "max-size": "10m", "max-file": "3" },
  "live-restore": true
}
systemctl restart docker
docker info --format '{{.LoggingDriver}} {{.DockerRootDir}}'
json-file /var/lib/docker

Add "data-root": "/data/docker" when /var is small (stop Docker and move the folder first).

  1. Use it without sudo — only for trusted admins. The docker group is the same as root on that host:
usermod -aG docker alice
newgrp docker
docker ps

On shared servers keep sudo docker, or use rootless mode.

23.3

Check that it worked

systemctl is-enabled docker
enabled
docker version --format '{{.Server.Version}}'
docker compose version
docker run --rm hello-world
Hello from Docker!

23.4

Common problems

ProblemCauseFix
Cannot connect to the Docker daemonThe service is not running, or no right on the socket.systemctl start docker; use sudo or the docker group.
permission denied … docker.sock after adding the groupThe group is read at login.Log out and in (or newgrp docker).
Package conflicts with podman / runc (RHEL)Podman packages are installed.Remove them first (step 1), or use Podman instead of Docker.
docker-compose: command not foundCompose v2 is a plugin: docker compose (space).Use docker compose; install docker-compose-plugin.
Disk full under /var/lib/dockerOld images, build cache, big logs.docker system df; prune; log rotation (step 4).
Published ports open although the firewall denies themDocker writes its own firewall rules.Bind to 127.0.0.1:PORT when a proxy is in front.

23.5

Go further

1Why is adding a user to the docker group a security decision?

A member can start a container that mounts / and change any file — it is like root.

2Where do you set log rotation for all containers?

In /etc/docker/daemon.json (log-opts max-size and max-file), then restart Docker.

Alle commando's in dit hoofdstuk