"fatal: unable to auto-detect email address" in DOCKER

Viewed 494

My docker run is failing because git complains that I didnt set a user config which I never needed for my older images.

From git.mysite.com:user/project
 * branch            dev -> FETCH_HEAD
*** Please tell me who you are.
Run
   git config --global user.email "you@example.com"
   git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'root@V_2_compute1.(none)')

I have two Dockerfiles which are quite similar but behave differently.

The first one with nvcr.io/nvidia/tensorflow:20.02-tf1-py3 as its source and the second one with nvcr.io/nvidia/tensorflow:20.12-tf2-py3. The first is a Ubuntu 18.04 and the second one Ubuntu 20.04. When inspecting the containers, they have different git versions (2.17.1 vs 2.25.1) but I'm not sure if this is the problem.

Here are the two Dockerfile (simplified):

# syntax=docker/dockerfile:experimental

FROM nvcr.io/nvidia/tensorflow:20.02-tf1-py3 as intermediate

ARG SSH_PRIVATE_KEY

RUN apt-get update \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y git \
&& mkdir /srv/username \
&& cd /srv/username
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan git.mysite.com >> ~/.ssh/known_hosts
ADD "https://www.random.org/cgi-bin/randbyte?nbytes=10&format=h" skipcache
RUN --mount=type=ssh git clone -b master git@git.mysite.com:user/project.git /srv/username/project
ENV PYTHONPATH "${PYTHONPATH}:/srv/username/project"
CMD /usr/sbin/service ssh restart && cd /srv/username/project && git pull origin feature-branch && git checkout feature-branch \
&& /srv/username/project/script.py 

The problematic one:

# syntax=docker/dockerfile:experimental

FROM nvcr.io/nvidia/tensorflow:20.12-tf2-py3 as intermediate

ARG SSH_PRIVATE_KEY

RUN apt-get update \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y git \
&& mkdir /srv/username \
&& cd /srv/username
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan git.mysite.com >> ~/.ssh/known_hosts
ADD "https://www.random.org/cgi-bin/randbyte?nbytes=10&format=h" skipcache
RUN --mount=type=ssh git clone -b master git@git.mysite.com:user/project.git /srv/username/project
ENV PYTHONPATH "${PYTHONPATH}:/srv/username/project"
CMD /usr/sbin/service ssh restart && cd /srv/username/project && git pull origin dev && git checkout dev \
&& /srv/username/project/script.py

Why do I now have to config a user in the latest ?

1 Answers

I didn't find why the error occured but I found a solution to remove it. Instead of cloning master then pulling the branch, I directly clone the branch I want to use.

The cloning line is now :

RUN --mount=type=ssh git clone --single-branch -b dev git@git.mysite.com:user/project.git /srv/username/project

Notice the use of -b dev with --single-branch to clone only the specified branch.

I am still not sure why the error occured in one case but not in the other. It might be because --mount=type=ssh can't be used in last CMD but then it should have failed in both case.

Related