Dockerfile

Learn which instructions can be used in Dockerfile.

Dockerfile

A Dockerfile is a plain-text file describing the steps to build an image, typically for your own application. To build a Docker image from a Dockerfile in the current directory, enter:

docker image build -t <image_name> .

The period at the end of the command references the current directory. Append -f <file> to use an alternative path or file name.

The commands below will be used most often.

# comment

Lines beginning with # denote a comment:

#my comment

ARG arguments

Variables can be passed at build time with the --build-arg <name>=<value> option. The value is imported with an ARG statement:

#get myvar
ARG myvar

A default value can be defined when nothing is passed:

#get myvar, with default of "myimage"
ARG myvar=myimage

Use its value elsewhere by prepending a $ symbol:

RUN echo $myvar

Where the value must be set in part of a string, a ${name} substitution can be defined:

FROM ${myvar}:latest

ENV environment variables

Set an environment variable:

 ...