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

What is the difference between the COPY and ADD commands in a Dockerfile?

Câu trả lời

The COPY and ADD commands in a Dockerfile are both used to copy files and directories from the host system into a Docker image, but they have distinct differences and use cases.

COPY Command

  • Purpose: The COPY command is used to copy files and directories from the host system into the Docker image.
  • Syntax: COPY <src> <dest>
  • Functionality: It only supports copying local files and directories from the host to the Docker image.
  • Use Case: It is recommended for straightforward file copying tasks because it is more transparent and predictable. It does not have any additional functionalities like handling URLs or extracting compressed files[1][2][3][4][5][6][7].

ADD Command

  • Purpose: The ADD command is more versatile and can handle additional tasks beyond just copying files.
  • Syntax: ADD <src> <dest>
  • Functionality:
    • Copying Local Files: Similar to COPY, it can copy local files and directories.
    • Handling URLs: It can download files from a URL and add them to the Docker image.
    • Extracting Archives: It can automatically extract compressed files (e.g., .tar, .tar.gz, .bz2, .xz) into the Docker image.
  • Use Case: It is useful when you need to download files from a URL or automatically extract compressed files. However, it should be used with caution because its additional functionalities can lead to unexpected behavior, such as unintentional file extraction[1][2][3][4][5][6][7].

#...

junior

junior

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

junior

What are the various states that a Docker container can be in at any given point in time?

middle

Explain a use case for Docker

senior

Can you run Docker containers natively on W

Bình luận

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

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