November 22, 2018

RUN --mount - Dockerfile frontend experimental syntaxes

Dockerfile frontend experimental syntaxes

You can build images with BuildKit on Docker 18.06 or later. With BuildKit, RUN instructions in Dockerfile accept --mount option. It can be used as a volume for build-time. For example, RUN --mount=type=cache,target=/var/cache/apt apt-get install ... means “Mount /var/cache/apt as a cache directory while running the command”. The cache remains in Docker host machine until you remove it with docker builder prune. In other words, you can share cache files among two or more build without writing them in the images.

To use these experimental features today, you have to enable BuildKit and put a comment # syntax=docker/dockerfile:experimental in the first line of your Dockerfile. BuildKit can be enabled as follows:

  • Docker 18.06 or later: put "experimental": true into the /etc/docker/daemon.json and set export DOCKER_BUILDKIT=1 before build.
  • Docker 18.09 or later: put "features": {"buildkit": true} into the /etc/docker/daemon.json or set export DOCKER_BUILDKIT=1 before build.

(c) Hibariya Lerche 2018

Powered by Hugo & Kiss.