DockerFile - Instruction

Instruction

FROM

LABEL

# Set one or more individual labels
LABEL com.example.version="0.0.1-beta"
LABEL vendor="ACME Incorporated"
LABEL com.example.release-date="2015-02-12"
LABEL com.example.version.is-production=""

RUN

Tool installation (note: the package are sorted in alphabetical order)

RUN apt-get update && apt-get install -y \
        package-bar \
        package-baz \
        package-foo

More … DockerFile - Run command

ARG

Defines argument that can be passed by the build command line

See Dockerfile - ARG instruction (argument)

ADD /COPY

  • COPY only supports the basic copying of local files into the container,
  • ADD has some features (like local-only tar extraction and remote URL support) that are not immediately obvious.

COPY is preferred.

COPY them individually, rather than all at once. This ensures that each step’s build cache is only invalidated (forcing the step to be re-run) if the specifically required files change.

COPY ./apache2.conf /etc/apache2/apache2.conf
COPY ./php.ini /usr/local/etc/php/php.ini

Because image size matters, using ADD to fetch packages from remote URLs is strongly discouraged; you should use curl or wget instead. That way you can delete the files you no longer need after they’ve been extracted and you don’t have to add another layer in your image.

RUN mkdir -p /usr/src/things \
    && curl -SL http://example.com/big.tar.xz \
    | tar -xJC /usr/src/things \
    && make -C /usr/src/things all

Powered by ComboStrap