-->

mardi 20 décembre 2016

Docker : Dockerfile

Introduction :

First, to Dockerfile, we should read this definition extracted from docker web site : 
"Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession."

Second, the Dockerfile has this format :  


# Comment
INSTRUCTION arguments

From :

The instruction is not case-sensitive. However, convention is for them to be UPPERCASE to distinguish them from arguments more easily. Docker runs instructions in a Dockerfile in order. The first instruction must be `FROM` in order to specify the Base Image from which you are building.

FROM ImageName
# directive=value

The FROM structure is :


FROM image

Or 


FROM image:tag

Or 


FROM image@digest

From :

The Maintainer instruction allows you to set the Author field of the generated images.

Expose :

The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. EXPOSE does not make the ports of the container accessible to the host. To do that, you must use either the -pflag to publish a range of ports or the -P flag to publish all of the exposed ports. You can expose one port number and publish it externally under another number.

ENV:

The The ENV instruction sets the environment variable to the value . This value will be in the environment of all “descendant” Dockerfile commands and can be replaced inline in many as well.

The ENV instruction has two forms. The first form, ENV , will set a single variable to a value. The entire string after the first space will be treated as the - including characters such as spaces and quotes.

The second form, ENV = ..., allows for multiple variables to be set at one time. Notice that the second form uses the equals sign (=) in the syntax, while the first form does not. Like command line parsing, quotes and backslashes can be used to include spaces within values.


ENV JAVA_HOME /dir_to_java

ADD:

The ADD has two forms:


ADD "src"... "dest"
ADD ["src",... "dest"] (this form is required for paths containing whitespace)

The ADD instruction copies new files, directories or remote file URLs from and adds them to the filesystem of the image at the path .

Multiple resource may be specified but if they are files or directories then they must be relative to the source directory that is being built (the context of the build).


ADD test relativeDir/          # adds "test" to `WORKDIR`/relativeDir/
ADD test /absoluteDir/         # adds "test" to /absoluteDir/

COPY:

The COPY has two forms:


COPY "src"... "dest
COPY ["src",... "dest"] (this form is required for paths containing whitespace)

The COPY instruction copies new files or directories from and adds them to the filesystem of the container at the path .

Multiple resource may be specified but they must be relative to the source directory that is being built (the context of the build).


COPY test relativeDir/   # adds "test" to `WORKDIR`/relativeDir/
COPY test /absoluteDir/  # adds "test" to /absoluteDir/




Aucun commentaire :

Enregistrer un commentaire