Forwarding ssh key using docker composer-compose
In docker 18.09+
we can use the following approach to use a forwarded ssh key when building an image:
# syntax=docker/dockerfile:experimental
# example file
FROM node:10.15.3-alpine
RUN apk update && apk add openssh-client git
# use the forwarded ssh key
RUN --mount=type=ssh git clone <repo>
Then we would build the image like this:
DOCKER_BUILDKIT=1 docker build --ssh default .
I would like to use docker-compose
to achieve this, but it does not seem to work. There is no --ssh
flag for the docker-compose command and I can't see anything I can set in the docker-compose.yml
file to accomplish this.
Unfortunately I think this is currently not supported, based on comments on this issue: https://github.com/docker/compose/issues/6358 -- in fact, googling for "docker-compose BuildKit" gives some links to various tickets all appearing to point to the fact that using BuildKit is not currently supported by docker-compose.
The workaround I would try (as well as mentioned in some of these ticket comments) is to build the images seperately, with a shell script calling "docker build", before running docker-compose.