Dockerfile command Summary

Source: Internet
Author: User

The command format isINSTRUCTION arguments, Commands includeFROM,MAINTAINER,RUN.

From

Format:FROM <image>OrFROM <image>:<tag>.

The first command must beFROMCommand. In addition, if you create multiple images in the same dockerfile, you can use multipleFROMCommand (once for each image ).

Maintainer

Format:MAINTAINER <name>, Specify the maintainer information.

Run

Format:RUN <command>OrRUN ["executable", "param1", "param2"].

The former will run commands in the shell terminal, that is/bin/sh -cThe latter usesexecRun. The second method can be used to specify other terminals, for exampleRUN ["/bin/bash", "-c", "echo hello"].

Each entryRUNThe command runs the specified command on the basis of the current image and submits it to the new image. You can use\Line feed.

CMD

Three formats are supported.

  • CMD ["executable","param1","param2"]UseexecExecution, recommended methods;
  • CMD command param1 param2In/bin/sh;
  • CMD ["param1","param2"]ProvidedENTRYPOINT;

Specify the command to be executed when the container is started. Each dockerfile can have only oneCMDCommand. If multiple commands are specified, only the last one will be executed.

If you specify the running command when starting the container, it will overwriteCMDThe specified command.

Expose

Format:EXPOSE <port> [<port>...].

Inform the docker server of the port number exposed by the container for the interconnected system.

Env

Format:ENV <key> <value>. Specify an environment variable.RUNCommand used and maintained during container running.

For example

ENV PG_MAJOR 9.3ENV PG_VERSION 9.3.4RUN curl -SL http://example.com/postgres-$PG_VERSION.tar.xz | tar -xJC /usr/src/postgress && …ENV PATH /usr/local/postgres-$PG_MAJOR/bin:$PATH
Add

Format:ADD <src> <dest>.

This command will copy the specified<src>To the container<dest>. Where<src>It can be a relative path of the directory where dockerfile is located, a URL, or a tar file (automatically decompressed as a directory ). .

Copy

Format:COPY <src> <dest>.

Copy<src>(The relative path of the directory where dockerfile is located)<dest>.

We recommend that you use the local directory as the source directory.COPY.

Entrypoint

Two formats:

  • ENTRYPOINT ["executable", "param1", "param2"]
  • ENTRYPOINT command param1 param2(Executed in shell ).

Configure the commands executed after the container is started and cannot bedocker runThe provided parameters are overwritten.

Each dockerfile can contain only oneENTRYPOINTWhen multiple are specified, only the last one takes effect.

Volume

Format:VOLUME ["/data"].

Create a mount point that can be mounted from a local host or other containers. It is generally used to store databases and data to be maintained.

User

Format:USER daemon.

Specify the username or uid when running the container.RUNThe specified user is also used.

When the service does not require administrator permission, you can use this command to specify the user to run. In addition, you can create the required users before, for example:RUN groupadd -r postgres && useradd -r -g postgres postgres. You can usegosuBut not recommendedsudo.

Workdir

Format:WORKDIR /path/to/workdir.

For subsequentRUN,CMD,ENTRYPOINTCommand to configure the working directory.

MultipleWORKDIRCommand. If the parameters of subsequent commands are relative paths, they are based on the paths specified by the previous commands. For example

WORKDIR /aWORKDIR bWORKDIR cRUN pwd

The final path is/a/b/c.

Onbuild

Format:ONBUILD [INSTRUCTION].

Configure the operation commands executed when the created image is used as the basic image of another newly created image.

For example, dockerfile creates an image using the following content:image-A.

[...]ONBUILD ADD . /app/srcONBUILD RUN /usr/local/bin/python-build --dir /app/src[...]

If a new image is created based onFROM image-AWhen the basic image is specifiedONBUILDCommand content, equivalent to adding two commands later.

FROM image-A#Automatically run the followingADD . /app/srcRUN /usr/local/bin/python-build --dir /app/src

UseONBUILDThe image of the command, which should be specified in the label, for exampleruby:1.9-onbuild.

Dockerfile command Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.