Mark Estrada
Mark Estrada

Reputation: 9191

Docker Authentication Private Git Dockerfile

I need to include some files from a private git repository thru the ADD command in my dockerfile since it supports URL as source.

But I dont know how to set the authentication. I am getting forwarded into the login page so when the image is created. It is the login page of the git repository.

FROM myimage
ARG version
LABEL Name="sample" Version="$version"

RUN mkdir -p /tmp/configs
ADD <private git> /tmp/configs

Any hints?

Upvotes: 0

Views: 843

Answers (1)

Abylay Sabirgaliyev
Abylay Sabirgaliyev

Reputation: 726

ADD can't be used to clone repository. It only downloads direct file links.

But you can clone your repository before building an image.

  1. Specify in Dockerfile what you want to add from the repo.

    FROM myimage

    RUN mkdir -p /tmp/configs

    ADD repo_root/inner_dir /tmp/configs

  2. Clone the repository and build an image.

    $(git clone git@***.git) && docker build . ; $(rm -rf repo_root)

This will clone the repository, build an image and delete repository directory.

Upvotes: 1

Related Questions