What are the most common instructions in a dockerfile

下次还敢
Release: 2024-04-07 19:21:21
Original
712 people have browsed it

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:

<code>FROM ubuntu:20.04</code>
Copy after login

2. RUN

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

Example:

<code>RUN apt-get update && apt-get install -y nginx</code>
Copy after login

3. COPY

  • Copy local files or directories to the container Mirroring.

Example:

<code>COPY index.html /usr/share/nginx/html</code>
Copy after login

4. ADD

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

Example:

<code>ADD myapp.tar.gz /usr/local/myapp</code>
Copy after login

5. CMD

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

Example:

<code>CMD ["nginx", "-g", "daemon off;"]</code>
Copy after login

6. EXPOSE

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

Example:

<code>EXPOSE 80</code>
Copy after login

7. ENV

  • Set environment variables.

Example:

<code>ENV APP_NAME myapp</code>
Copy after login

8. VOLUME

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

Example:

<code>VOLUME /var/log/myapp</code>
Copy after login

9. WORKDIR

  • Set the working directory in the container.

Example:

<code>WORKDIR /usr/local/myapp</code>
Copy after login

10. ENTRYPOINT

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

Example:

<code>ENTRYPOINT ["/usr/local/myapp/bin/myapp"]</code>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template