Einführung in Docker
Tim Sangster
Software Engineer @ DataCamp
Das Hello-World-Image gibt Text aus und stoppt dann.
docker run hello-world
Hello from Docker!
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon created a new container from the hello-world image which runs the
executable that produces the output you are currently reading.
3. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
Ein Image mit Python könnte Python beim Start öffnen.
docker run python3-sandbox
Python 3.10.6 (main, Nov 2 2022, 18:53:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
...
....
>>> exit()
repl@host:/#
CMD <shell-command>
Die CMD-Anweisung:
Starten einer Anwendung, um einen Workflow auszuführen oder externe Verbindungen zuzulassen
CMD python3 my_pipeline.py
CMD postgres
Ein Skript starten, das dann mehrere Anwendungen startet
CMD start.sh
CMD python3 start_pipeline.py
$$
$$
Ein allgemeineres Image braucht einen allgemeineren Startbefehl.
Ein Image starten
docker run <image>
Ein Image mit einem benutzerdefinierten Startbefehl starten
docker run <image> <shell-command>
Ein Image interaktiv mit einem benutzerdefinierten Startbefehl starten
docker run -it <image> <shell-command>
docker run -it ubuntu bash
| Verwendung | Dockerfile-Anweisung |
|---|---|
| Shell-Befehl hinzufügen, der ausgeführt wird, wenn ein Container aus dem Image gestartet wird | CMD <shell-command> |
| Verwendung | Shell-Befehl |
|---|---|
| Das im Image eingestellt CMD überschreiben | docker run <image> <shell-command> |
| Das im Image eingestellte CMD überschreiben und interaktiv starten | docker run -it <image> <shell-command> |
Einführung in Docker