Einführung in Docker
Tim Sangster
Software Engineer @ DataCamp

Eine Dockerfile startet immer von einem anderen Image, das mit der FROM-Anweisung angegeben wird.
FROM postgres
FROM ubuntu
FROM hello-world
FROM my-custom-data-pipeline
FROM postgres:15.0
FROM ubuntu:22.04
FROM hello-world:latest
FROM my-custom-data-pipeline:v1
Beim Bauen eines Dockerfiles wird ein Image erstellt.
docker build /location/to/Dockerfile
docker build .
[+] Building 0.1s (5/5) FINISHED
=> [internal] load build definition from Dockerfile
=> => transferring dockerfile: 54B
...
=> CACHED [1/1] FROM docker.io/library/ubuntu
=> exporting to image
=> => exporting layers
=> => writing image sha256:a67f41b1d127160a7647b6709b3789b1e954710d96df39ccaa21..
In der Praxis geben wir unseren Images fast immer mit dem Flag -t einen Namen:
docker build -t first_image .
...
=> => writing image sha256:a67f41b1d127160a7647b6709b3789b1e954710d96df39ccaa21..
=> => naming to docker.io/library/first_image
docker build -t first_image:v0 .
=> => writing image sha256:a67f41b1d127160a7647b6709b3789b1e954710d96df39ccaa21..
=> => naming to docker.io/library/first_image:v0
RUN <valid-shell-command>
FROM ubuntu
RUN apt-get update
RUN apt-get install -y python3
Nutze das Flag -y, um alle Eingabeaufforderungen zu überspringen:
...
After this operation, 22.8 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Docker braucht genauso viel Zeit, um RUN apt-get update auszuführen, wie wir!
root@host:/# apt-get update
Get:1 http://ports.ubuntu.com/ubuntu-ports jammy InRelease [270 kB]
...
Get:17 http://ports.ubuntu.com/ubuntu-ports jammy-security/restricted arm64 Pack..
Fetched 23.0 MB in 2s (12.3 MB/s)
Reading package lists... Done
| Verwendung | Dockerfile-Anweisung |
|---|---|
| Dockerfile aus Image starten | FROM <image-name> |
| Shell-Befehl zum Image hinzufügen | RUN <valid-shell-command> |
| Sicherstellen, dass für den Shell-Befehl keine Benutzereingaben nötig sind | RUN apt-get install -y python3 |
| Verwendung | Shell-Befehl |
|---|---|
| Image aus Dockerfile erstellen | docker build /location/to/Dockerfile |
| Image im aktuellen Arbeitsverzeichnis erstellen | docker build . |
| Beim Erstellen eines Images einen Namen festlegen | docker build -t first_image . |
Einführung in Docker