What is the difference between ...
What is the difference between ...
In Docker, RUN, CMD, and ENTRYPOINT are three distinct instructions used in Dockerfiles, each serving a different purpose in the lifecycle of a Docker container. Here’s a detailed explanation of the differences between them:
RUN instruction is used to execute commands in a new layer on top of the current image and commit the results. This is typically used for installing software packages or making other modifications to the image.RUN <command>RUN ["executable", "param1", "param2"]RUN apt-get update && apt-get install -y python3
CMD instruction provides default arguments for the ENTRYPOINT instruction or specifies the default command to run when a container is started. It is overridden if any command is provided at runtime.CMD <command>CMD ["executable", "param1", "param2"]CMD ["param1", "param2"] (used to provide default parameters to the ENTRYPOINT)CMD ["python3", "app.py"]
ENTRYPOINT instruction configures a container to run as an executable. It specifies a command that will always be executed when the container starts. Unlike CMD, ENTRYPOINT is not overridden by the command line arguments provided at runtime; instead, those arguments are passed as parameters to the ENTRYPOINT.senior