1

I'm working on a Dockerfile. It's an Ubuntu 18.04 image with ROS melodic, I need to clone a few repositories while building the Docker image using git.

Normally, I'd generate a new SSH key and add that key to my GitHub account but things are different now because to do what I typically do, I'll have to build the Docker image, run it, and then clone (& build) the git repositories.

Also, I will be distributing this Docker image, and I don't really want to link these repositories to my account with an SSH key.

So far this is what I tried:

# Create a non-root user whom can sudo
RUN useradd -ms /bin/bash -G sudo <username>
RUN echo '<username>:<password>' | chpasswd

# Create a workspace and set WORKDIR
<...>

# Set git defaults
COPY --chown=<username>:<username> .gitconfig /home/<username>
COPY .gitconfig /root

# Clone the git repository
ARG ghname
ARG ghtoken
RUN git clone https://$ghname:$ghtoken@github.com/<organization>/<repo>.git

This attempt failed:

Step 20/30 : Copy --chown=<username>:<username> .gitconfig /home/<username>
COPY failed: file not found in build context or excluded by .dockerignore: stat .gitconfig: file does not exist
...
...
Cloning into '<repo>'...
remote: Repository not found.
fatal: Authentication failed for 'https://:@github.com/<organization>/<repo>.git/'

Then I tried:

# Create a non-root user whom can sudo
RUN useradd -ms /bin/bash -G sudo <username>
RUN echo '<username>:<password>' | chpasswd

# Create a workspace and set WORKDIR
<...>

# Clone the git repository
git clone git@github.com:<organization>/<repo>.git

This attempt failed (as expected):

Cloning into '<repo>'...
fatal: unable to fork
The command '/bin/sh -c git clone git@github.com:<organization>/<repo>.git' returned a non-zero code: 128
csg
  • 8,096
  • 3
  • 14
  • 38
  • You write "This attempt failed:" but did not provide the actual command you ran, like `docker build ...`. – SebDieBln Mar 02 '22 at 17:41
  • The error message "file not found in build context" is pretty clear. There is no `.gitconfig` in your build-context (usually the directory the `Dockerfile` is in). That is not surprising since `.gitconfig` probably lives in your home-directory which is most likely (hopefully!) not your build-context. Again, the actual command you execute would help. – SebDieBln Mar 02 '22 at 17:47

0 Answers0