2

I have multiple web applications (app1, app2, app3... appN), each interacting with each other (over http). Each of the web app will be running in a separate docker container. Each app is installed by installing the code from git, setting up the database defaults and running some initializations. All of the apps will be running in a single host (each developer will have his/her copy of all the apps on their system).

The owner of app3 (for ex) wouldn't bother or know about other apps setting, and will be happy to just take the default settings of other apps. The QA team will also have no knowledge of setting up apps, relying on default configuration.

Note: The git repository is password authenticated.

The requirement is to have:

  • Create docker containers for each app, with default configurations, so that all the apps (installed via docker-compose) are pre-configured and starts without any additional effort.
  • Ability to update latest code changes into the docker containers

Well, docker is a great solution and we could accomplish most of them. However, the following are issues:

  1. During the docker build process, there is no support for env variables (and unlikely to be). But we cannot hard code git repository credentials in the Dockerfile. We need a pre-configured app setup, but I am unable to figure a easier way to get the code from git into the docker image.

  2. For simple changes in git code base, there is no need to create a new docker image. Instead, it should be okay to run "git pull" from within the container. (Also, for a developer of that app, can also do "git push" from within the container itself - making dev testing easier). For all of this, the git credentials need to be of that particular developer, who is using this.

  3. It would be too clumsy to have the git repositories installed on the host and referred using docker volumes (-v). [ If a developer wishes to do so, they could still do that - but I would not prefer this as default ]

Any suggestions welcome!

1 Answer 1

3

The easier way to get your app into your Docker image is usually to use the ADD command.

Assuming your repository looks like this:

.git
my_app_stuff/
more_app_stuff/

Then just drop your Dockerfile next to .git, and use:

ADD . /app

When you run docker build . from that directory, your app will be injected into the container at /app.

Now, that doesn't quite do it, since it'll also load .git into your image, which you might want to avoid (especially if you've included credentials in .git/config!).

To fix this, simply tell Docker that it should ignore this directory by adding a .dockerignore plaintext file containing .git.

In the end, your tree should look like this:

.dockerignore
.git
my_app_stuff/
more_app_stuff/

Note that if a developer wants to, they can use -v ... to mount their local copy of the app at /app and overwrite the one that's built into the image.


Now, that does not quite solve your problem as far as being bale to git pull from the container goes.

If you actually want to do this, you'll want to keep .git in there, and ensure valid credentials are somehow passed to your container when you launch it (perhaps through a volume or an environment variable).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I do want to keep the .git inside the container/image (for git pull, and as well git push - sometimes). I just noticed that the credentials by default are not kept within the .git local folder of the repository (though one could store it). IOW, the result of git clone done by two users are identical in their output. That gives flexibility to keep the entire git clone folder within the docker image, but somehow get the valid credentials during git pull/push. Looking to see if that can be stored in a local redis / etcd container.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.