Introduktion till Docker
Tim Sangster
Software Engineer @ DataCamp
hello-world-imagen skriver ut text och avslutas sedan.
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.
En image med python kan starta Python vid uppstart.
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>
CMD-instruktionen:
Starta ett program som kör ett arbetsflöde eller tar emot externa anslutningar.
CMD python3 my_pipeline.py
CMD postgres
Starta ett skript som i sin tur startar flera program
CMD start.sh
CMD python3 start_pipeline.py
$$
$$
En mer generell image behöver ett mer generellt startkommando.
Starta en image
docker run <image>
Starta en image med ett anpassat startkommando
docker run <image> <shell-command>
Starta en image interaktivt med ett anpassat startkommando
docker run -it <image> <shell-command>
docker run -it ubuntu bash
| Användning | Dockerfile-instruktion |
|---|---|
| Lägg till ett shell-kommando som körs när en container startas från imagen. | CMD <shell-command> |
| Användning | Shell-kommando |
|---|---|
| Åsidosätt CMD i imagen | docker run <image> <shell-command> |
| Åsidosätt CMD i imagen och kör interaktivt | docker run -it <image> <shell-command> |
Introduktion till Docker