Docker - dockerfile

> Virtualization - (Virtual Machine|Container) > Docker > Docker - dockerfile

1 - About

A Dockerfile specifies instructions on how to create an image.

See Computer Language

A Dockerfile describes the software that is “baked” into an image. It isn’t just ingredients though, it can tell the software what environment to use or what commands to run.

Advertising

3 - Example

  • A Dockerfile has no extension
Dockerfile
from ...
 
RUN ["apt-get", "update"]
RUN ["apt-get", "install", "-y", "vim"]

4 - Docker file Syntax / Structure

When developing a dockerfile, some docker instruction will create layers (also known as commit)

  • In Docker 1.10 and higher, only RUN, COPY, and ADD instructions create layers. Other instructions create temporary intermediate images, and no longer directly increase the size of the build.
  • Docker 17.05 and higher add support for multi-stage builds, which allow you to copy only the artifacts you need into the final image. This allows you to include tools and debug information in your intermediate build stages without increasing the size of the final image.

4.1 - Multi-stage

With multi-stage builds, you use multiple FROM statements in your Dockerfile.

If you use Docker 17.05 or higher, you can use multi-stage builds to drastically reduce the size of your final image

4.2 - Structure

Your build stage may contain several layers, ordered from the less frequently changed to the more frequently changed for example:

  • Install tools you need to build your application
  • Install or update library dependencies
  • Generate your application
Advertising

4.2.1 - Tools

RUN apt-get update && apt-get install -y \
  bzr \
  cvs \
  git \
  mercurial \
  subversion

5 - Documentation / Reference

vm/docker/dockerfile/dockerfile.txt · Last modified: 2019/10/07 19:45 by gerardnico