6

I currently have a Docker compose based web app that uses Nginx as a reverse proxy that forwards traffic to a Flask and Grafana docker instance. The task at hand is to integrate a SSG (static site generator) such as Jekyll into the setup.

The most straight forward approach is to:

  1. have a Jekyll container continually run and serve the static aspect of the site via Nginx redirects (jekyll serve).
  2. Another approach would be to run the build command in the Jekyll docker image and have the output be shared via docker volumes with Nginx.
  3. Yet another is to generate the site in the Nginx container

The downside with the first two solutions is that they create a Jekyll docker instance that is only used once and then persists. In 1.'s case, the serving can be directly handled by Nginx. In 3.'s case, there is no separation between Jekyll and Nginx. This would be useful since Nginx is also responsible for routing traffic to the other Docker instances.

The question is, is there a way to populate a Docker volume with a Dockerfile by Jekyll so that this can then be mounted by Nginx? Step by step:

  1. docker-compose build: build the site and populate the static-site volume
  2. docker-compose up -d: Nginx mounts the static-site volume and serves it

Does this approach even make sense?

1 Answer 1

5

docker-compose is just a glorified wrapper around docker which gives you a nice textual representation of all the options you would regularly give to docker build or docker run. Plus, of course, it bundles several docker images/containers together. That said, it has no provisions to run anything else than you would get by calling docker.

I don't see how you would use docker-compose build to populate a volume. Volumes are, by definition, not living inside docker images/containers, but outside (on the host system). docker build never writes to the host system, and you cannot mount volumes during docker build. docker-compose build basically only runs docker build for you, and also has no way to run or write anything on the host.

So, no, docker-compose build will not be able to create the static files.

You could make your compose file so that it runs your generator (inside a docker container, writing to a named volume), and runs your server (nginx or whatever) in another container, mounting the same named volume (this would be your case 2, I believe). Then, with docker-compose up, it would fire up both those containers. The first one would populate your static files; the second would serve. The first would hang around and do nothing afterwards, which you could just ignore, but which would certainly be ugly. Unfortunately, you cannot use something like docker-compose up --rm to automatically the unneccessary jekyll container.

So, your best bet is to start the jekyll container yourself (docker run --rm jekyll:xyz -v ...:...), the --rm will remove the container after it is finished. Then docker-compose up with the actual server(s).

2
  • I actually had to do a small work-around. First run Jekyll (SSG), copy the HTML site it output into a named volume via a busybox container, and then mount the volume. How and where should I post the relevant code?
    – Moritz
    Commented Feb 11, 2018 at 8:12
  • @Moritz, glad that you got it to work. You can do a self-answer here, or just edit your question.
    – AnoE
    Commented Feb 11, 2018 at 9:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.