Introducere în Docker
Tim Sangster
Software Engineer @ DataCamp
Imaginea hello-world afișează text și apoi se oprește.
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.
O imagine cu Python poate porni Python la inițializare.
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>
Instrucțiunea CMD:
Pornirea unei aplicații pentru a rula un flux de lucru sau care acceptă conexiuni externe.
CMD python3 my_pipeline.py
CMD postgres
Pornirea unui script care, la rândul său, pornește mai multe aplicații
CMD start.sh
CMD python3 start_pipeline.py
$$
$$
O imagine mai generală necesită o comandă de start mai generală.
Pornirea unei imagini
docker run <image>
Pornirea unei imagini cu o comandă de start personalizată
docker run <image> <shell-command>
Pornirea interactivă a unei imagini cu o comandă de start personalizată
docker run -it <image> <shell-command>
docker run -it ubuntu bash
| Utilizare | Instrucțiune Dockerfile |
|---|---|
| Adaugă o comandă shell executată la pornirea unui container din imagine. | CMD <shell-command> |
| Utilizare | Comandă shell |
|---|---|
| Suprascrie comanda CMD din imagine | docker run <image> <shell-command> |
| Suprascrie comanda CMD din imagine și rulează interactiv | docker run -it <image> <shell-command> |
Introducere în Docker