Closed oddg closed 5 years ago
Humm it might be related to the custom setup of git credentials...
Actually the following does work...
# syntax=docker/dockerfile:1.0.0-experimental
# syntax=docker/dockerfile:experimental
FROM ubuntu:18.04
RUN apt-get -yq update && apt-get -yqq install ssh git
# Set up a `git credentials` helper for using GH_USER and GH_TOKEN to access
# private repositories if desired.
ADD git-credential-ghtoken /usr/local/bin
RUN git config --global credential.https://github.com.helper ghtoken
RUN mkdir -m 700 ~/.ssh && touch -m ~/.ssh/known_hosts && ssh-keyscan github.com > ~/.ssh/known_hosts
RUN --mount=type=ssh,id=github git clone git@github.com:my-company/my-private-repo.git ~/my-private-repo
The issue is triggered by running command with the rust user. The following fails:
# syntax=docker/dockerfile:1.0.0-experimental
# syntax=docker/dockerfile:experimental
FROM ubuntu:18.04
RUN apt-get -yq update && apt-get -yqq install ssh git
RUN useradd rust --user-group --create-home --shell /bin/bash --groups sudo
ADD sudoers /etc/sudoers.d/nopasswd
USER rust
RUN mkdir -m 700 ~/.ssh && touch -m ~/.ssh/known_hosts && ssh-keyscan github.com > ~/.ssh/known_hosts
RUN --mount=type=ssh,id=github git clone git@github.com:my-company/my-private-repo.git ~/my-private-repo
Yup, that seems about right. Sorry about that. :-/ You do have the option of using sudo
in the Rust image if you want, but it's probably better to use USER root
followed by the commands you want to run, then USER rust
to set it back.
We also bundle an example git
credential helper, which shows how to do more complicated authentication with git
.
@emk Thanks for the suggestion! Running USER root
does fix the issue. In the end I am going with:
# syntax=docker/dockerfile:1.0.0-experimental
# syntax=docker/dockerfile:experimental
FROM ekidd/rust-musl-builder
RUN sudo apt-get -yq update && sudo apt-get -yqq install ssh git
USER root
RUN mkdir -m 700 ~/.ssh && touch -m ~/.ssh/known_hosts && ssh-keyscan github.com > ~/.ssh/known_hosts
RUN --mount=type=ssh,id=github git clone git@github.com:my-company/my-private-repo.git /home/rust/my-private-repo
RUN chown -R rust:rust /home/rust/coin-or-clp
USER rust
I am trying to use the --ssh option of the docker build command. I can successfully use it with ubuntu as a base image
but it fails when I use ekidd/rust-musl-builder
Running the command
DOCKER_BUILDKIT=1 docker build --ssh github=~/.ssh/id_rsa .
gives me the following error message:It's unclear to me what in the rust-musl-builder image may break the --ssh.
Here is my docker version: