In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you what Dockerfile commonly used instructions refer to, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can gain something through the detailed introduction of this article.
The most commonly used instructions in Dockerfile are listed below.
FROM
Specifies the base image.
MAINTAINER
Sets the author of the mirror, which can be any string.
COPY
Copy the file from build context to the mirror.
COPY supports two forms:
COPY src dest
COPY ["src", "dest"]
Note: src can only specify files or directories in build context.
ADD
Similar to COPY, files are copied 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
Set the environment variable, which can be used by the following instructions. For example:
...
ENV MY_VERSION 1.3
RUN apt-get install-y mypackage=$MY_VERSION
...
EXPOSE
The process in the specified container listens on a port that Docker can expose. We will discuss it in detail in the container network section.
VOLUME
Declare a file or directory as volume. We will discuss it in detail in the container storage section.
WORKDIR
Set the current working directory in the image for subsequent RUN, CMD, ENTRYPOINT, ADD, or COPY instructions.
RUN
Runs the specified command in the container.
CMD
Runs the specified command when the 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 command to run when the container 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:
Directory bunch: the archive file bunch.tar.gz copied from build context by the ADD instruction has been automatically unzipped.
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.
Among the above instructions, RUN, CMD, and ENTRYPOINT are important and easily confused, which are discussed in the next section.
The above is what the commonly used Dockerfile instructions refer to. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.