Introduction to Docker
Tim Sangster
Software Engineer @ DataCamp
The hello-world image prints text and then stops.
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.
An image with python could start python on startup.
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>
The CMD instruction:
Starting an application to run a workflow or that accepts outside connections.
CMD python3 my_pipeline.py
CMD postgres
Starting a script that, in turn, starts multiple applications
CMD start.sh
CMD python3 start_pipeline.py
$$
$$
A more general image needs a more general start command.
Starting an image
docker run <image>
Starting an image with a custom start command
docker run <image> <shell-command>
Starting an image interactively with a custom start command
docker run -it <image> <shell-command>
docker run -it ubuntu bash
Usage | Dockerfile Instruction |
---|---|
Add a shell command run when a container is started from the image. | CMD <shell-command> |
Usage | Shell Command |
---|---|
Override the CMD set in the image | docker run <image> <shell-command> |
Override the CMD set in the image and run interactively | docker run -it <image> <shell-command> |
Introduction to Docker