Skip to main content

Difference between entrypoint and CMD in Dockerfile or Docker

Difference between entrypoint and CMD in Dockerfile or Docker.

CMD is nothing but argument to the EntryPoint by default docker uses “/bin/sh -c” as an entry point. So if we are defining only CMD in docker file it uses “/bin/sh -c” for example,
If dockerfile will having below format,
CMD [“bash”]
Default command which docker container will run, will be “/bin/sh -c bash”
If dockerfile will having below format,
CMD [“ping 8.8.8.8 -c 4”]
Default command which docker container will run, will be “/bin/sh -c ping 8.8.8.8 -c 4”
If dockerfile will having below format,
ENTRYPOINT [“/bin/ping”]
CMD [“ 8.8.8.8 -c4”]
Default command which docker container will run, will be “/bin/ping 8.8.8.8 -c 4”
If dockerfile will having below format,
ENTRYPOINT [“/bin/ping”,”-c”,”4”]
CMD [“8.8.8.8”]
Default command which docker container will run, will be “/bin/ping -c 4 8.8.8.8”

Comments