Wprowadzenie do Dockera
Tim Sangster
Software Engineer @ DataCamp
Obraz hello-world wyświetla tekst i zatrzymuje się.
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.
Obraz z Pythonem może uruchamiać Pythona przy starcie.
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>
Instrukcja CMD:
Uruchamianie aplikacji obsługującej przepływ pracy lub przyjmującej połączenia zewnętrzne.
CMD python3 my_pipeline.py
CMD postgres
Uruchamianie skryptu, który z kolei uruchamia wiele aplikacji
CMD start.sh
CMD python3 start_pipeline.py
$$
$$
Bardziej ogólny obraz wymaga bardziej ogólnego polecenia startowego.
Uruchamianie obrazu
docker run <image>
Uruchamianie obrazu z niestandardowym poleceniem startowym
docker run <image> <shell-command>
Interaktywne uruchamianie obrazu z niestandardowym poleceniem startowym
docker run -it <image> <shell-command>
docker run -it ubuntu bash
| Zastosowanie | Instrukcja Dockerfile |
|---|---|
| Dodaje polecenie powłoki uruchamiane przy starcie kontenera. | CMD <shell-command> |
| Zastosowanie | Polecenie powłoki |
|---|---|
| Nadpisanie CMD ustawionego w obrazie | docker run <image> <shell-command> |
| Nadpisanie CMD i uruchomienie interaktywne | docker run -it <image> <shell-command> |
Wprowadzenie do Dockera