Introdução ao Docker
Tim Sangster
Software Engineer @ DataCamp
A imagem hello-world imprime texto e encerra.
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.
Uma imagem com python pode iniciar o python ao subir.
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>
A instrução CMD:
Iniciar um app para rodar um workflow ou aceitar conexões externas.
CMD python3 my_pipeline.py
CMD postgres
Iniciar um script que por sua vez inicia vários apps
CMD start.sh
CMD python3 start_pipeline.py
$$
$$
Uma imagem mais geral precisa de um comando inicial mais geral.
Iniciando uma imagem
docker run <image>
Iniciando com um comando inicial personalizado
docker run <image> <shell-command>
Iniciando interativamente com um comando inicial
docker run -it <image> <shell-command>
docker run -it ubuntu bash
| Uso | Instrução no Dockerfile |
|---|---|
| Adicionar um comando de shell executado quando um contêiner é iniciado a partir da imagem. | CMD <shell-command> |
| Uso | Comando de shell |
|---|---|
| Substituir o CMD definido na imagem | docker run <image> <shell-command> |
| Substituir o CMD e rodar interativamente | docker run -it <image> <shell-command> |
Introdução ao Docker