Issue with github access tokens

So I have a dockerfile that contains the code:

ARG git_personal_token
ENV git_personal_token $git_personal_token 
RUN git clone https://crooksey:${git_personal_token}@github.com/crooksey/myrepo.git

(The ENV # line is not required locally, but have added as some Docker guides suggest its required, still fails with same reasons.) I can also try using $git_personal_token without the {} and again works locally, not on dockerhub.

I then build my Dockerfile locally with:

$ docker build -t mycontainer:v0 . --build-arg git_personal_token=ghp_MYPERSONALACCESSTOKEN

This works fine on a few local machines, but the code in Dokcerhub causes the error:

#20 [ 9/17] RUN git clone https://crooksey:${git_personal_token}@github.com/crooksey/myrepo.git
#20 0.370 Cloning ...
#20 1.361 remote: Invalid username or password.

On my dockerhub build settings, I do have “git_personal_token” in my build environment variables.

This does not work, but If I update the Dockerfile to include a hard-coded access token, it builds correctly.

RUN git clone https://crooksey:ghp_MYPERSONALACCESSTOKEN@github.com/crooksey/myrepo.git

Seems very strange and I can’t work out why this might be, could my builds somehow be ignoring my build environment variables?

Just to be sure: your build hook uses the argument --build-arg git_personal_token=${git_personal_token} to pass the build environment variable into the image build?

In case of unclearity, please share the content of hooks/build as it will help to understand what you actualy use to build the image.

I have updated the original post to include more details.

Shouldn’t it be like this?
docker build --build-arg git_personal_token=${git_personal_token} -t mycontainer:v0 .

Also I strongy suggest to remove the ENV, as it would persist your personal token in the image history and would be available in every contaiener created from that image.