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.

    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.

    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.

    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.

    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.

    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.

    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.

    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.

    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.

    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.

    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

expert

Can you explain a relationship between container runtime and container orchestration?

senior

What is an orphant volume and how to remove it?

junior

What’s the difference between a repository and a registry?

Bình luận

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

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