About
A Dockerfile specifies instructions on how to create an image.
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.
Example
- A Dockerfile has no extension
from ...
RUN ["apt-get", "update"]
RUN ["apt-get", "install", "-y", "vim"]
- Inkscape with X11
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.
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
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
Tools
RUN apt-get update && apt-get install -y \
bzr \
cvs \
git \
mercurial \
subversion