What are the most common instructions in Dockerfile?
What are the most common instructions in Dockerfile?
The most common instructions in a Dockerfile are essential for defining the steps to build a Docker image. Here are the key instructions:
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
LABEL: This instruction adds metadata to an image in ...
junior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào