WORKDIR: This instruction defines the working directory. If not specified / is the default workdir
CMD:
This instruction is executed when the container is created and can be overritten by passing arguments when creating container
ENTRYPOINT:
This instruction is executed when the container is created and cannot be overritten by passing arguments when creating container
Generally in entrypoint we give executable path and in CMD we give arguments for the containers where the command to be executed when starting containers is fixed.
java -jar spc.jar
Give flexibility to run anything during creating container
CMD ["java", "-jar", "spc.jar"]
Dont give flexibility
ENTRYPOINT ["java", "-jar", "spc.jar"]
Give option on arguments to be passed
ENTRYPOINT ["java"]
CMD ["-jar", "spc.jar"]
We should be using ENTRYPOINT/CMD instructions to wait till the application is running
When we run applications we have two types of startups
commands which will start the application will not return till the application is killed. For these kind of applications directly add the command to CMD
Examples: java -jar <package>.jar, python main.py
commands which will start the application and will return immedietly. For these type of commands we need to look for alternative so that command will continue running as long as application is running.