Die Installation und Konfiguration von Docker ist der erste Schritt zur Nutzung der Containerisierungsplattform. Docker kann auf verschiedenen Betriebssystemen installiert werden, darunter Linux, Windows und macOS. In diesem Kapitel wird die Installation und grundlegende Konfiguration von Docker unter Linux beschrieben.
Bevor Docker installiert wird, sollten einige grundlegende Voraussetzungen erfüllt sein:
Befehl (Debian/Ubuntu):
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Befehl (Debian/Ubuntu):
sudo apt-get update
sudo apt-get install -y docker-ce
Überprüfung der Installation:
Befehl:
sudo docker --version
Ausgabe:
Docker version 20.10.7, build f0df350
Befehl:
sudo systemctl start docker
sudo systemctl enable docker
Überprüfung des Dienststatus:
Befehl:
sudo systemctl status docker
Ausgabe:
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-07-05 10:05:17 CEST; 1h 2min ago
Um Docker-Befehle ohne sudo
ausführen zu können, kann
der Benutzer zur Docker-Gruppe hinzugefügt werden.
Befehl:
sudo usermod -aG docker $USER
Hinweis: Nach Ausführung dieses Befehls muss der Benutzer sich ab- und wieder anmelden, damit die Änderung wirksam wird.
Die Datei /etc/docker/daemon.json
wird zur Konfiguration
des Docker-Daemons verwendet. Änderungen an dieser Datei erfordern einen
Neustart des Docker-Dienstes.
Beispielkonfiguration:
{
"log-driver": "json-file",
"log-level": "warn",
"storage-driver": "overlay2"
}
Neustarten des Docker-Dienstes:
Befehl:
sudo systemctl restart docker
Falls Docker hinter einem Proxy betrieben wird, müssen Proxy-Umgebungsvariablen konfiguriert werden.
Beispielkonfiguration:
Datei: /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"
Environment="HTTPS_PROXY=https://proxy.example.com:443/"
Neustarten des Docker-Dienstes:
Befehl:
sudo systemctl daemon-reload
sudo systemctl restart docker
Docker-Daemon kann mit zusätzlichen Optionen gestartet werden, um bestimmte Einstellungen zu aktivieren.
Beispiel: Aktivieren des Debug-Modus
Befehl:
sudo dockerd --debug
Nach der Installation und Konfiguration von Docker kann ein einfacher Test durchgeführt werden, um sicherzustellen, dass Docker korrekt funktioniert.
Befehl:
docker run hello-world
Ausgabe:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
478afc919002: Pull complete
Digest: sha256:94323f3e5e09a8b9515d74337010375a456c909543e1ff1538f5116d38ab3989
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(arm64v8)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/