0

I'm trying to build docker image with this docker file and I need to clone some private repositories from bitbucket.

FROM ubuntu

RUN chsh -s /bin/bash



RUN apt-get update
RUN apt-get install -y git python-pip

ADD private_key_for_deployment /root/.ssh/id_rsa
RUN chmod 600 /root/.ssh/id_rsa
RUN echo "StrictHostKeyChecking no" >> /root/.ssh/config
RUN echo >> /root/.ssh/config
RUN echo "Host bitbucket.org" >> /root/.ssh/config

RUN cat /root/.ssh/id_rsa
RUN mkdir -p /usr/src/app/
COPY requirements.txt /usr/src/app/
RUN cat /root/.ssh/config
WORKDIR /usr/src/app/
RUN  echo "IdentityFile ~/.ssh/id_rsa" >> /root/.ssh/config
RUN eval "$(ssh-agent)" && \
    ssh-add && \
    ssh-add -l \
    pip install -U -r requirements.txt
COPY . /usr/src/app

WORKDIR /usr/src/app/data_service/
CMD ["python" "data_service.py"]

I've also tried without ssh-add -l

I need to say that this key if working perfectly inside docker container. I've generated the key inside this container started ssh agent added the identity and I'm able to clone repositories there.

EDIT1

This happens when building docker image:

Step 15 : RUN eval "$(ssh-agent)" && ssh-add && pip install -U -r requirements.txt
---> Running in 2b9a79fa7cf3
Agent pid 8
Enter passphrase for /root/.ssh/id_rsa: 2015/07/02 22:26:46 The command [/bin/sh -c eval "$(ssh-agent)" && ssh-add && pip install -U -r requirements.txt] returned a non-zero code: 1

  • When does it show the prompt? When you do the docker build .? Please add that detail to your Q if it is so. – slm Jul 3 '15 at 2:42
  • Yes. Sorry, I forgot to add the output. I've edited the question. – user1685095 Jul 3 '15 at 6:16
1

You specified the private key as /root/.ssh/id_rsa. Does the script run as root? As here "IdentityFile ~/.ssh/id_rsa" >> /root/.ssh/config you tell it to look under the current user's home directory rather than specifically /root/.ssh/id_rsa. It's behaving as if you're passing it the wrong key.

I don't use docker but maybe that might be relevant to your problemn.

  • Yes. Everything in docker happens as root. – user1685095 Jul 3 '15 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.