Wayne Werner
Wayne Werner

Reputation: 51787

Is it possible to use a private git(hub) repo in Dockerfile ADD?

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?

Upvotes: 2

Views: 581

Answers (2)

Eli
Eli

Reputation: 38899

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.

Upvotes: 0

Abdullah Jibaly
Abdullah Jibaly

Reputation: 54780

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.

Upvotes: 1

Related Questions