17
loading...
This website collects cookies to deliver better user experience
CMD
and ENTRYPOINT
instructions defined in a Dockerfile, used to describe how a Docker container should be run.Once the process stops, the container stops as well.
FROM
command, defining a base image to build our image upon. We usually follow up with a bunch of RUN
instructions, used to run commands which modify the underlying filesystem.Each RUN
instruction creates a new image layer that contains a modification to the filesystem.
CMD
and ENTRYPOINT
are two different types of instructions used to define how a Docker container should be run. CMD
instruction defines the default command used to run a Docker container from an image.FROM alpine
CMD ["echo", "Hello, World!"]
docker container run my-container
Hello, World!
A Dockerfile can contain multiple CMD
instructions, but every single one of them, except for the last one, will be ignored.
CMD
instruction can be overridden by the arguments passed to docker container run
, like:docker container run my-container echo "Hello again!"
Hello again!
ENTRYPOINT
instructions define, just like their CMD siblings, the default command used to start a container.FROM alpine
ENTRYPOINT ["echo", "Hello, World!"]
Hello, World!
CMD
and ENTRYPOINT
instructions are defined inside a Dockerfile, the CMD
instruction will be concatenated to the ENTRYPOINT
one:FROM alpine
ENTRYPOINT ["echo"]
CMD ["Hello, World!"]
Hello, World!
CMD
instructions are, by design, made do be easily overridden by passing arguments to docker container run
commands, ENTRYPOINT
have purposely been made harder to override manually, by forcing user to use a --entrypoint
flag.ENTRYPOINT
to define a base command which always gets executed, and CMD
to define default arguments for this command, easily overridable by passing custom args to docker container run
.17