0

I have a dockerfile. In which i have to clone a repository from bitbucket using https url but how am i suppose to pass a password to make the clone complete? And yes i tried ssh .it works but i need https clone for some shell script to run so that it should automatically accepts the password.

Here is my docker command to clone repo:

RUN git clone https://username@bitbucket.org/abc/xyz.git

And here is the error i get while buildind docker file : \

Cloning into 'newfolder'... fatal: could not read Password for 'https://username@bitbucket.org': No such device or address

MY build command is :

sudo docker build --no-cache=true -t image:build .

tushar patil
  • 359
  • 2
  • 4
  • 13
  • 1
    Possible duplicate of [Is there a way to skip password typing when using https:// on GitHub?](https://stackoverflow.com/questions/5343068/is-there-a-way-to-skip-password-typing-when-using-https-on-github) – Ferrybig Aug 25 '17 at 08:58

1 Answers1

7

You can specify the password in the url as such:

git clone https://username:password@bitbucket.org/abc/xyz.git

If you don't want to hardcode the password in the dockerfile, you can pass it as a build arg.

ARG password
RUN git clone https://username:$password@bitbucket.org/abc/xyz.git

sudo docker build --build-arg password=pass --no-cache=true -t image:build .

yamenk
  • 46,736
  • 10
  • 93
  • 87
  • i tried that but still i get following error : Cloning into 'newfolder'... fatal: unable to access 'https://username:@password123@bitbucket.org/abc/xyz.git/': Could not resolve host: password123@bitbucket.org – tushar patil Aug 25 '17 at 09:41
  • your password starts with @. It is being interpreted as a host. You need to escape the @ character by %40 – yamenk Aug 25 '17 at 09:57