28
loading...
This website collects cookies to deliver better user experience
docker run debian echo hello
docker run debian
Dockerfile
s. Note that these are oversimplified versions of these files (except for Debian).CMD
instruction at the bottom which tells them to run some command. In the case of Debian, it issues just bash
which is just a shell, not a process. If you already spotted, both Redis
and nginx
Dockerfiles have definitions to spin up their processes - the Redis server and Nginx web server, respectively.docker run debian echo hello-world
CMD
instruction in our Dockerfile, there are 3 ways to specify this according to Docker docs.CMD ["executable","param1","param2"]
(exec form, this is the preferred form)CMD ["param1","param2"]
(as default parameters to ENTRYPOINT)CMD command param1 param2
(shell form)💡 There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.
FROM debian
CMD ["printf", "Hello from Test1"]
docker run test1 hello
, it will result in a “starting container process caused: exec: “hello”: executable file not found in $PATH: unknown.” error.docker run test1 printf hello
but that beats the purpose of having a Dockerfile in the first place.FROM debian
ENTRYPOINT ["printf", "Hello from %s\n"]
CMD ["Test2"]
ENTRYPOINT
instruction says Docker that whatever we have specified there, must be run when the container starts. In other words, if we are to pass in arguments, they will get appended to what we have specified there as the ENTRYPOINT.docker build -t test -f Test2.Dockerfile .
CMD
instruction we had at line no. 3; but it will still show the output as we have defined in our ENTRYPOINT. This makes sense since there can be only one CMD instruction per container.28