2

There are plenty of questions about cloning a git repo into a container by installing git and then cloning stuff. What I'm interested in doing is something more like this, where they use a GitHub URL in the ADD command.

Obviously that's just a public URL, though.

Is it possible to use something like git over ssh or scp or something in my Dockerfile to get files into my image?

Community
  • 1
  • 1
Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
  • Can you give more information about your use-case? I'm almost certain you don't actually want this because the key you'd authenticate with would be accessible to anyone that has access to your docker image or a container running from it. – Eli Jan 07 '15 at 04:59
  • I have code in git/hg, and I want to get it into a docker container, but I don't want to require git/hg in that container. Does that make sense? – Wayne Werner Jan 07 '15 at 05:15

2 Answers2

1

It's not possible yet because docker build doesn't support build-time parameters, although I think this feature may be coming soon. You'll have to do a build using the docker context for now.

For example, if you look at the way hub.docker.com auto-build works, you have to add a deploy key into the github repo that allows their build servers to read that repo.

Abdullah Jibaly
  • 53,220
  • 42
  • 124
  • 197
0

Given the clarification in OP's comments that he's just trying to get git code into Docker, the easiest way to do this is by using the git repo as context for the docker build file. For example, if I want code from my repo to be added to /usr/local/git/my_repo in the docker image, I'd put the Dockerfile in the root of my image and do:

ADD ./ /usr/local/git/my_repo

If you need some other repo added, this is generally something you want your automation system (i.e. Ansible, Puppet, Chef, etc...) to handle. Have your automation system pull down whatever repo(s) you need, and then move your Dockerfile to the root folder that contains all needed repos and do (assuming you'd like all of them in a folder called "my_repos" in the image):

ADD ./ /my_repos

You can expand on the idea from here, but the main tl;dr; to take away is, it's best and easiest to add stuff to a Docker image as context, and to let your automation system handle the authentication and process needed to initially get whatever stuff you want added and arrange it around the Dockerfile your building from.

Eli
  • 36,793
  • 40
  • 144
  • 207
  • The main reason I wanted something different than your idea is so that I wasn't worried about where the files were locally - as long as someone had say, SSH credentials, they would be able to build from the Dockerfile and I didn't have to worry about where they put their code repo. Though now that I'm rubber ducking it, I think add *would* actually work. – Wayne Werner Jan 08 '15 at 14:56