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

What are the most common instructions in Dockerfile?

Câu trả lời

The most common instructions in a Dockerfile are essential for defining the steps to build a Docker image. Here are the key instructions:

  1. FROM: This instruction sets the base image for the Docker image being built. It is typically the first instruction in a Dockerfile.

    dockerfile Copy
    FROM ubuntu:20.04

    [1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17]

  2. RUN: This instruction executes commands in a new layer on top of the current image and commits the results. It is often used to install software packages.

    dockerfile Copy
    RUN apt-get update && apt-get install -y python3

    [1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17]

  3. CMD: This instruction provides the default command to run when a container is started from the image. Only the last CMD instruction in the Dockerfile is used.

    dockerfile Copy
    CMD ["python3", "app.py"]

    [1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17]

  4. COPY: This instruction copies files or directories from the host machine into the Docker image.

    dockerfile Copy
    COPY . /app

    [1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17]

  5. ADD: Similar to COPY, but with additional features like extracting tar files and fetching files from URLs.

    dockerfile Copy
    ADD myfile.tar.gz /app

    [1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17]

  6. WORKDIR: This instruction sets the working directory for any subsequent instructions in the Dockerfile.

    dockerfile Copy
    WORKDIR /app

    [1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17]

  7. EXPOSE: This instruction informs Docker that the container listens on the specified network ports at runtime.

    dockerfile Copy
    EXPOSE 8080

    [1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17]

  8. ENV: This instruction sets environment variables.

    dockerfile Copy
    ENV APP_ENV=production

    [1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17]

  9. ENTRYPOINT: This instruction configures a container that will run as an executable.

    dockerfile Copy
    ENTRYPOINT ["python3", "app.py"]

    [1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17]

  10. VOLUME: This instruction creates a mount point with the specified path and marks it as holding externally mounted volumes from native host or other containers.

    dockerfile Copy
    VOLUME /data

    [1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17]

  11. LABEL: This instruction adds metadata to an image in ...

junior

junior

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

junior

Is there a way to identify the status of a Docker container?

senior

Is it possible to generate a Dockerfile from an image?

expert

Why Docker compose does not wait for a container to be ready before moving on to start next service
in dependency order?

Bình luận

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

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