What is dockerfile?
Dockerfile is a text file that contains commands for the combined image. It can be used to call any command on the command line. Docker by reading the Dockerfile
automatic generation of image instructions.
docker build
Command is used to construct an image from Dockerfile. You can docker build
use command -f
flag to the file system Dockerfile anywhere.
Example:
docker build -f /path/to/a/Dockerfile
The basic structure of Dockerfile
Dockerfile generally divided into four parts: the base image information, perform a maintainer information, instructions and image containers start command, '#' is the comment Dockerfile.
Dockerfile File Description
Docker Dockerfile instructions to run from top to bottom order. To specify the base image, the first instruction must be the FROM . A statement to #
the beginning of the character is considered a comment. Docker file can be used in RUN
, CMD
, FROM
, EXPOSE
, ENV
and other instructions.
Here are some commonly used commands ^ - ^
FROM: Specifies the base image, you must first command
MAINTAINER: maintainer information
RUN: command to execute when building mirror
ADD: adding local files to the container, tar will automatically unzip the file type (compression network resources are not unpacked), you can access network resources, similar to wget
COPY: functions like ADD, but is not automatically unzip the file, can not access network resources
CMD: After building container calls, which is invoked only when the container starts.
ENTRYPOINT: Configuration container, make it executable oriented. CMD can save with the "application", use only parameters.
LABEL: for adding metadata mirror
ENV: setting environment variables
EXPOSE: Specifies the port to interact with the outside world
VOLUME: is used to specify persistence directory
WORKDIR: working directory, similar to the cd command
USER: User name or UID run when the specified container, subsequent RUN will use the specified user. When using the USER specified user, the user can use the name, UID, or the GID, or a combination of both.
When the service does not require administrator privileges, you can specify a user to run this command. And you can create a user needs before
ARG: for variables that are passed to construct run
ONBUILD: setting a flip-flop mirror
Finally, a chart to explain the meaning of frequently used instructions ^ - ^
Details Original: https://www.cnblogs.com/panwenbin-logs/p/8007348.html