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)
The most common instructions in Dockerfile
The most commonly used instructions in Dockerfile are as follows:
1. FROM
Example:
<code>FROM ubuntu:20.04</code>
2. RUN
Example:
<code>RUN apt-get update && apt-get install -y nginx</code>
3. COPY
Example:
<code>COPY index.html /usr/share/nginx/html</code>
4. ADD
Example:
<code>ADD myapp.tar.gz /usr/local/myapp</code>
5. CMD
Example:
<code>CMD ["nginx", "-g", "daemon off;"]</code>
6. EXPOSE
Example:
<code>EXPOSE 80</code>
7. ENV
Example:
<code>ENV APP_NAME myapp</code>
8. VOLUME
Example:
<code>VOLUME /var/log/myapp</code>
9. WORKDIR
Example:
<code>WORKDIR /usr/local/myapp</code>
10. ENTRYPOINT
Example:
<code>ENTRYPOINT ["/usr/local/myapp/bin/myapp"]</code>
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!