Authenticate to repo from image build

I am trying to connect to a private github repo using a token. I have tried a few variations and still get the error though I am using a token. Thank you :).

From alpine:3.15.4


RUN apk add --no-cache --virtual build_deps \
git  \
  && git config --global url."https://${TOKEN}".insteadOf "" \
  && git clone https://${TOKEN} --branch=main

Build with:

docker image build -t test:1.0.0 --build-arg TOKEN={xxxxx} .

fatal: Authentication failed for ''
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead

Try this instead of your git clone:

git clone https://${TOKEN} --branch=main

So just don’t set the username. It worked for me with your Dockerfile

1 Like

Thank you very much, that worked :).