Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The most commonly used instructions in Dockerfile

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

FROM specifies the base image. The author of the MAINTAINER setting image, which can be any string. COPY copies files from build context to the mirror. COPY supports two forms: COPY src destCOPY ["src", "dest"] Note: src can only specify files or directories in build context. ADD is similar to COPY in that it copies files from build context to the mirror. The difference is that if the src is an archive file (tar, zip, tgz, xz, etc.), the file will be automatically extracted to dest. ENV sets environment variables, which can be used by subsequent instructions. For example:... ENV MY_VERSION 1.3RUN apt-get install-y mypackage=$MY_VERSION...EXPOSE specifies that a process in the container will listen on a port that Docker can expose. We will discuss it in detail in the container network section. VOLUME declares a file or directory as volume. We will discuss it in detail in the container storage section. WORKDIR sets the current working directory in the image for subsequent RUN, CMD, ENTRYPOINT, ADD, or COPY instructions. RUN runs the specified command in the container. Runs the specified command when the CMD container starts. There can be multiple CMD instructions in Dockerfile, but only the last one takes effect. CMD can be replaced by parameters after docker run. ENTRYPOINT sets the commands that the container runs when it starts. There can be multiple ENTRYPOINT instructions in Dockerfile, but only the last one takes effect. Parameters after CMD or docker run are passed to ENTRYPOINT as parameters. Let's take a look at a more comprehensive Dockerfile:

Note: Dockerfile supports comments that start with "#". Build an image:

Before building the ①, make sure that the required files exist in the build context. ② executes Dockerfile instructions in turn to complete the build. Run the container to verify the contents of the image:

① enters the container and the current directory is WORKDIR. If WORKDIR does not exist, Docker will automatically create it for us. The files and directories we want are saved in ② WORKDIR: the directory bunch: the archive file bunch.tar.gz, copied from build context by the ADD instruction, has been automatically extracted. File tmpfile1: created by the RUN directive. File tmpfile2: copied from build context by the COPY instruction. The environment variable defined by the ③ ENV directive is already in effect.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report