Skip to content

Latest commit

 

History

History
65 lines (45 loc) · 1.04 KB

File metadata and controls

65 lines (45 loc) · 1.04 KB

ENTRYPOINT - CMD

  • CMD and ENTRYPOINT work similarly, they execute a command at container runtime

  • CMD can be overridden

  • ENTRYPOINT is good to accept parameters

  • Create this Dockerfile and build an image

FROM ubuntu
ENTRYPOINT ["sleep"]
  • build the image
docker build -t sleeper .
  • run as a container and see the result
docker run sleeper
  • you get the error saying that a parameter was missing

  • run again this time with a parameter

docker run sleeper 5
  • now you observe that the container waits 5 seconds to exit

  • modify the Dockerfile adding CMD. here CMD is used to give a default value in case parameter is forgotten.

FROM ubuntu
ENTRYPOINT ["sleep"]
CMD ["1"]

=======

  • a similar way can be applied on a sample node app file. here app.js is a default argument in case forgotten.
...
ENTRYPOINT ["node"]
CMD ["app.js"]

=======

  • rebuild the image
docker build -t sleeper .
  • run as a container
docker run sleeper