2

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.

1

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.

  • In the end I actually ditched this thing and used a oauth key created in github instead RUN git clone --single-branch --branch $BRANCH https://$OAUTH_TOKEN@<REPO> /src/app so to build you just add a build-arg OAUTH_TOKEN - docker build --build-arg BRANCH=<BRANCH> --build-arg OAUTH_TOKEN=<TOKEN> .. Doesn't feel really good using experimental features anyway =) – Cyclonecode Jun 21 '19 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.