Syncing from GitLab to Docker Host Volume

This week I was asked to help solve a problem encountered during a POC.

The team were working with an application in a docker container which needs to read configuration data on startup.

Rather than having the configuration data baked into the container, the application reads it from a docker data volume which is mapped to a directory on the host.

The configuration data was copied to the host, the volumes and directories mapped and the application tested successfully.

The configuration data files are maintained in a git repository, and for the first test these had just been copied to the host.  However, the team were asked if we could keep the configuration data in sync with the git repository, so we'd have something like:


Not something I had done before.  However I was fairly sure that I wasn't the first.


  • I had a quick search on dockerhub and found an image that looked useful:  https://hub.docker.com/r/openweb/git-sync/
  • Basically it polls a git repo and clones it to a directory in the container that is mapped to a docker volume, and so to a directory on the host.
  • I tested it against a public repo on github and checked that it not only cloned the repo, but also synchronised subsequent changes.
  • Then I pointed to the URL for the config repo.
    • I had to include the username and password in the URL
    • I had to set --network==host to use the SSH tunnel between the host and the GitLab server.
    • I also needed to set the environment variable GIT_SSL_NO_VERIFY=true, otherwise it fails with an SSL verification error
  • Issued the docker run command and it worked :-)
Of course if you wanted to get fancy you could use WebHooks from GitLab to trigger a "clone on commit", and the networking and security could probably be improved upon, but it did the job.

Comments

Popular posts from this blog

Wot no FDK?

The Case of the Vanishing Dockerfile

Honey I Shrunk The Container