Câu hỏi phỏng vấn Docker
Câu hỏi

What is the difference between ...

Câu trả lời

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

  • Purpose: The 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.
  • Usage: It is executed during the build process of the Docker image, not at runtime.
  • Forms:
    • Shell form: RUN <command>
    • Exec form: RUN ["executable", "param1", "param2"]
  • Example:
    dockerfile Copy
    RUN apt-get update && apt-get install -y python3

CMD

  • Purpose: The 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.
  • Usage: It is executed at runtime, but only if no other command is specified when the container is started.
  • Forms:
    • Shell form: CMD <command>
    • Exec form: CMD ["executable", "param1", "param2"]
    • Parameter form: CMD ["param1", "param2"] (used to provide default parameters to the ENTRYPOINT)
  • Example:
    dockerfile Copy
    CMD ["python3", "app.py"]

ENTRYPOINT

  • Purpose: The 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.
  • Usage: It is executed at runtime and is intended to be the...
senior

senior

Gợi ý câu hỏi phỏng vấn

middle

How can we control the startup order of services in Docker compose?

senior

What is Paravirtualization?

junior

What is Docker container?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào