From b3d0dfb704e8b022cfaa8daa30dfeabcdf30fcf3 Mon Sep 17 00:00:00 2001 From: hiepxanh Date: Fri, 4 Jun 2021 15:14:04 +0700 Subject: [PATCH] docs: dockerfiles buildkit add cache directory ex Add example how to cache directory on dockerfile --- docs/deployment/builders/dockerfiles.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/deployment/builders/dockerfiles.md b/docs/deployment/builders/dockerfiles.md index 581fb41e2..56eaf29b5 100644 --- a/docs/deployment/builders/dockerfiles.md +++ b/docs/deployment/builders/dockerfiles.md @@ -77,6 +77,17 @@ RUN echo $NODE_ENV If your Dockerfile is using Docker engine's [buildkit](https://docs.docker.com/develop/develop-images/build_enhancements/) (not to be confused with buildpacks), then the `DOCKER_BUILDKIT=1` environment variable needs to be set. One way to do this is to edit `/etc/environment` on your dokku host and reboot your instance. Note, for complete build log output, you should also set `BUILDKIT_PROGRESS=plain` in the same file. +Buildkit has implemented the RUN --mount option which lets you mount a cache directory for your run commands. E.g. here's one that mounts some of the debian directories (with a reconfigure of the debian image, this could speed up reinstalls of packages): +```Dockerfile +FROM debian:latest +RUN --mount=target=/var/lib/apt/lists,type=cache \ + --mount=target=/var/cache/apt,type=cache \ + apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + git +``` +You would adjust the cache directory for whatever application cache you have, e.g. `/root/.pnpm-store/v3` for pnpm, `$HOME/.m2` for maven, or `/root/.cache` for golang. + ### Customizing the run command By default no arguments are passed to `docker run` when deploying the container and the `CMD` or `ENTRYPOINT` defined in the `Dockerfile` are executed. You can take advantage of docker ability of overriding the `CMD` or passing parameters to your `ENTRYPOINT` setting `$DOKKU_DOCKERFILE_START_CMD`. Let's say for example you are deploying a base Node.js image, with the following `ENTRYPOINT`: