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?