Perl programmer for hire: download my resume (PDF).
John Bokma's Hacking & Hiking

Running pdflatex Using the Alpine Pandoc LaTeX Docker Image

June 20, 2021

I use a custom Perl script which uses pdflatex to generate invoices for my customers. Currently the program runs in a VirtualBox virtual machine (Ubuntu). But since I want to switch to Apple Silicon in the near future I am currently moving several programs to Docker. I was able to make the Perl program, after a few minor modifications, on macOS except for the external call to pdflatex. Since I want to reduce the number of programs I have to install directly on macOS I decided to "dockerize" pdflatex.

Because I want the Docker image to be small I started out with an Alpine image. But installing texlive-full resulted in an image of several gigabytes! After a few experiments I decided to see if I could just run pdflatex from a Pandoc Docker image I already needed for creating my resume.

$ docker run --rm --entrypoint pdflatex resume-pandoc
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021) (preloaded forma
t=pdflatex)
 restricted \write18 enabled.
**
! End of file on the terminal... why?

Because this image is "just" 686.6MB I decided to try to create a new image using pandoc-latex as a base:

# syntax=docker/dockerfile:1
FROM pandoc/latex:latest

ENTRYPOINT ["pdflatex"]

I build the Docker image using:

docker build -t pdflatex .

When running the container using:

docker run --rm --volume "`pwd`:/data" --user `id -u`:`id -g` pdflatex \
    invoice.tex

I got the following error message:

! LaTeX Error: File `sectsty.sty' not found.

Since I had seen the same error when building the image I use to create my resume I already knew the solution: install the missing package using tlmgr. So I updated the Dockerfile:

# syntax=docker/dockerfile:1
FROM pandoc/latex:latest

RUN tlmgr update --self && tlmgr install sectsty

ENTRYPOINT ["pdflatex"]

Running the newly created image resulted in another error:

! LaTeX Error: File `lastpage.sty' not found.

So I added this package as well, resulting in:

# syntax=docker/dockerfile:1
FROM pandoc/latex:latest

RUN tlmgr update --self && tlmgr install sectsty lastpage

ENTRYPOINT ["pdflatex"]

This time I got yet another error, but one that was a bit harder to fix:

! Font T1/phv/m/n/10=phvr8t at 10.0pt not loadable: Metric (TFM) file not found
.

A font was missing, but which one, and which package to install? Googling the error message gave a quick answer: helvetic. Adding this to the installation step resulted in a working image; I now could generate a PDF invoice from a TeX input file.

# syntax=docker/dockerfile:1
FROM pandoc/latex:latest

RUN tlmgr update --self && tlmgr install sectsty lastpage helvetic

ENTRYPOINT ["pdflatex"]