Introductie tot Docker
Tim Sangster
Software Engineer @ DataCamp
De hello-world-image print tekst en stopt daarna.
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.
Een image met python kan python bij het opstarten starten.
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>
De CMD-instructie:
Een applicatie starten om een workflow te draaien of die externe verbindingen accepteert.
CMD python3 my_pipeline.py
CMD postgres
Een script starten dat op zijn beurt meerdere apps start
CMD start.sh
CMD python3 start_pipeline.py
$$
$$
Een algemener image heeft een algemenere startopdracht nodig.
Een image starten
docker run <image>
Een image starten met een aangepaste startopdracht
docker run <image> <shell-command>
Een image interactief starten met een aangepaste startopdracht
docker run -it <image> <shell-command>
docker run -it ubuntu bash
| Gebruik | Dockerfile-instructie |
|---|---|
| Voeg een shell-opdracht toe die draait wanneer een container uit het image wordt gestart. | CMD <shell-command> |
| Gebruik | Shell-opdracht |
|---|---|
| Overschrijf de in het image ingestelde CMD | docker run <image> <shell-command> |
| Overschrijf de ingestelde CMD en draai interactief | docker run -it <image> <shell-command> |
Introductie tot Docker