This is how to build a Debian container for compiling LaTeX documents. For a project we had to build a complex report using a lot of LaTeX and Python features. This container provides a consistent build environment for all project participants. The LaTeX environment should be pretty complete.
This is only required once.
docker build -t claus/latex .
Per default we assume you have a project with a Makefile, so the docker container will run make
as an entrypoint (see below if you don't want to use make
):
docker run -u "$(id -u):$(id -g)" -it --name latexbuild --rm -v "$(pwd)":/mnt claus/latex # Build the report
docker run -u "$(id -u):$(id -g)" -it --name latexbuild --rm -v "$(pwd)":/mnt claus/latex clean # Clean up
docker run -u "$(id -u):$(id -g)" -it --name latexbuild --rm -v "$(pwd)":/mnt claus/latex --help # Get help
Explanation of parameters:
- -it : makes command interactive
- --name latexbuild : gives container a name
- --rm : deletes container afer use
- -v "$(pwd)":/mnt : creates bind mount for the local dir to /mnt in the container
- -u "$(id -u):$(id -g)" : run as current user and group inside container
The container is spawned from the image for every build and is discarded afterwards. Only files in the mounted report directory are modified.
If you do not have a Makefile, just set an empty entrypoint using the --entrypoint
argument to run any command, eg. pdflatex
:
docker run -u "$(id -u):$(id -g)" -it --name latexbuild --entrypoint "" --rm -v "$(pwd)":/mnt claus/latex pdflatex document.tex
docker run -u "$(id -u):$(id -g)" -it --name latexbuild -v "$(pwd)"/report:/mnt --entrypoint bash claus/latex
This is an alternative if you do not want to build the image, e.g. if you want to keep one state, and you want to have the image on multiple hosts.
docker save -o docker-latex.image claus/latex
docker load -i docker-latex.image