Search code examples
dockerboot2docker

Pass in variables or answer Dockerfile


This seems to be a frequently asked question. I'd like to ask it again to see if anyone has come up with an answer or to see if someone can suggest something else.

We have many computers and run services, and it's generally a headache to update them. In comes Docker. We'd like to automate this process. Docker will work well for this, but I would like to automate the build so anyone on our team can do that.

Part of the process involves cloning some git repositories.

One thing I could do is use a shell script to clone the repos locally and then copy them over to the image, but since there is a dockerfile that is suppose to automate stuff, it seems natural to put the directions in there.

This is not a problem except supplying git credentials.

Currently I'm copying over my id_rsa during the build process. The though is to copy it over, pull from the repo, and then remove my credentials. That should work fine except Dockerfile does not accept user input.

When I go to add my ssh key in the dockerfile, it wants my key password...docker just craps out as it can't take user input.

How do I get around this and still automate the process?

Here is a sample from the dockerfile.

FROM ubuntu:14.04
MAINTAINER Senica Gonzalez <senica@gmail.com>
RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get -y install git-core
RUN apt-get -y install vagrant
RUN mkdir /home/.ssh
COPY id_rsa /home/.ssh/id_rsa
RUN eval "$(ssh-agent -s)"; ssh-add /home/.ssh/id_rsa; ssh-add -l

Solution

  • One approach might be to do the git clone on the machine where you're doing docker build. Then the clone'd source files can be COPYed to the container.

    That keeps all the git key handling on your local machine and you don't have to worry about your ssh key being included in the Docker image.