3

I am trying to clone a private repository inside my docker container using ssh keys. I am using my own ssh keys by exporting it and then passing it in ARGS. Following is my docker file content

FROM python:3.6

WORKDIR /code

# Add credentials on build
ARG SSH_PRIVATE_KEY

# making direcotry
RUN mkdir /root/.ssh/
# wrting ssh_key to system
RUN echo $SSH_PRIVATE_KEY >> /root/.ssh/id_rsa && chmod 600 /root/.ssh/id_rsa
#RUN chmod 600 /root/.ssh/id_rsa
# adding git agents to hosts
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan -T 60 bitbucket.org >> /root/.ssh/known_hosts
# copying requirements
COPY ./requirements/private_requirements.txt /code/
# installing requirements
RUN pip install -r private_requirements.txt

But when i build it i am getting following error

---> Running in 65ef13750ea9 Collecting git+ssh://git@bitbucket.org/USERNAME/REPO.git (from -r private_requirements.txt (line 1)) Cloning ssh://git@bitbucket.org/USERNAME/REPO.git to /tmp/pip-req-build-3085swbp Warning: Permanently added the RSA host key for IP address '18.205.93.1' to the list of known hosts. Permission denied (publickey). fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists. Command "git clone -q ssh://git@bitbucket.org/PAK-SIGN/sso-consumer.git /tmp/pip-req-build-3085swbp" failed with error code 128 in None You are using pip version 10.0.1, however version 18.0 is available. You should consider upgrading via the 'pip install --upgrade pip' command. ERROR: Service 'connect' failed to build: The command '/bin/sh -c pip install -r private_requirements.txt' returned a non-zero code: 1

I am sure ARG SSH_PRIVATE_KEY has correct value and i have verified it by printing it. Please point out if there is a problem in my approach or suggest some other approach to achieve this. Thanks in advance.

Shoaib Iqbal
  • 2,420
  • 4
  • 26
  • 51
  • 1
    Trying running a `python:3.6` container via `docker run -it python:3.6 /bin/sh` , add your SSH key manually, and then try cloning the repository - see if you have any issues. Work your way up. – TJ Biddle Sep 11 '18 at 08:38
  • 2
    Possible duplicate of [Using SSH keys inside docker container](https://stackoverflow.com/questions/18136389/using-ssh-keys-inside-docker-container) – David Maze Sep 11 '18 at 09:47

0 Answers0