I have a docker container which I would like to build with buildkit sometimes and with standard docker build other times. Imagine we have a container like:
# syntax=docker/dockerfile:experimental
FROM python:3.8
# Install all necessary libraries into a pyenv environment
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts
RUN --mount=type=ssh pip install -r api-requirements.txt
We use the --mount=type=ssh
flag to tell buildkit to use the ssh keys here when we're pip installing things from our private repository. Everything works fine when you use Buildkit for building with the following command:
ssh-add && cd api && DOCKER_BUILDKIT=1 docker build --no-cache --ssh default -t image-name .
However, we can no longer build this container with standard docker commands like:
docker build -t image-name .
because the --mount
flag is not recognized. Is there anyway to use the same Dockerfile without editing it with both buildkit and normally? Can one tell Docker to just ignore these flags?
There's an open RFC issue for this considering if a way to ignore unknown flags would be useful. However doing this automatically for any unknown flag is likely to cause more breakages than it fixes. For example with the mounting of ssh credentials, it's very likely that the build would fail without the credentials.
In this situation, the advice tends to be either maintaining a separate Dockerfile for buildkit based builds with all the features and manually keeping them in sync, or pushing to have all the builds done with either buildkit or the classic builder, but not both.