Junior — Middle
What is the purpose of the CMD command when creating a Dockerfile and how does it affect the container's startup?
sobes.tech AI
Answer from AI
The CMD command in a Dockerfile specifies the command that will be executed by default when the container starts. It defines the main process of the container. If no other command is specified when starting the container, CMD will be executed.
Example:
FROM openjdk:11
COPY app.jar /app.jar
CMD ["java", "-jar", "/app.jar"]
In this example, the Java application will automatically start when the container runs. If a different command is specified at startup, it will override CMD.