Home>Article>Operation and Maintenance> What are the most common instructions in a dockerfile

What are the most common instructions in a dockerfile

下次还敢
下次还敢 Original
2024-04-07 19:21:21 470browse

The most commonly used instructions in Dockerfile are: FROM: Create a new image or derive a new image RUN: Execute commands (install software, configure the system) COPY: Copy local files to the image ADD: Similar to COPY, it can automatically decompress tar archive or get the URL file CMD: Specify the command when the container starts EXPOSE: Declare the container listening port (but not public) ENV: Set the environment variable VOLUME: Mount the host directory or anonymous volume WORKDIR: Set the working directory in the container ENTRYPOINT: Specify The executable file to be executed when the container starts (similar to CMD, but cannot be overridden)

What are the most common instructions in a dockerfile

The most common instructions in Dockerfile

The most commonly used instructions in Dockerfile are as follows:

1. FROM

  • Create a new container image or derive a new image from a base image .

Example:

FROM ubuntu:20.04

2. RUN

  • Execute the command in the container. Typically used to install software or configure the system.

Example:

RUN apt-get update && apt-get install -y nginx

3. COPY

  • Copy local files or directories to the container Mirroring.

Example:

COPY index.html /usr/share/nginx/html

4. ADD

  • is similar to COPY, but can be solved automatically Compress a tar archive or get a file from a URL.

Example:

ADD myapp.tar.gz /usr/local/myapp

5. CMD

  • Specify the command to be executed when the container starts .

Example:

CMD ["nginx", "-g", "daemon off;"]

6. EXPOSE

  • States the port that the container will listen on, but The port is not actually exposed in the Docker daemon.

Example:

EXPOSE 80

7. ENV

  • Set environment variables.

Example:

ENV APP_NAME myapp

8. VOLUME

  • Mount the host directory or anonymous volume to in the container.

Example:

VOLUME /var/log/myapp

9. WORKDIR

  • Set the working directory in the container.

Example:

WORKDIR /usr/local/myapp

10. ENTRYPOINT

  • Specify the executable to be executed when the container starts executable file. Similar to CMD, but not overridable.

Example:

ENTRYPOINT ["/usr/local/myapp/bin/myapp"]

The above is the detailed content of What are the most common instructions in a dockerfile. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn