Original question from pandoc discuss.

To build an Docker image allowing pandoc --pdf-engine=lualatex test.md -o test.pdf with the source file test.md as follow:

mainfont: TeX Gyre Termes

Lorem ipsum ttt

Background info about pandoc's Docker image

The official Docker image pandoc/latex:latest installed TeXLive under /opt whose write access is reserved for root user. By default, a container is run with root.

$ docker run --rm --entrypoint="" pandoc/latex:latest sh -c 'whoami'

To run pandoc using Docker, converting README.md to README.pdf:

$ docker run --rm --volume "$(pwd):/data" --user $(id -u):$(id -g) \
pandoc/latex README.md -o README.pdf

source: pandoc installing #Docker

! $(pwd) takes everything in current directory to /data in the Docker container built from image pandoc/latex:latest, then the container runs pandoc README.md -o README.pdf with the user and group privileges in the base system, and ends, The output README.pdf remains after the container has ended. The --rm is included so that it's not recorded in the list of containers docker ps.

Background info about Docker's USER

To avoid running as root in a Docker container, one can specify the USER name in Dockerfile.


I tried compiling test.md with my Dockerfile, which used the identity USER pptruser of a normal user, and I got an unhelpful message showing a "fatal error". To know more about the problem, I first converted test.md to test.tex locally with

$ pandoc -s test.md -o test.tex

before I compiled it with LuaLaTeX in the Docker container built with my Dockerfile.

$ docker run --rm --volume "$(pwd):/home/pptruser" --user $(id -u):$(id -g) \
customDockerImage:1.0 --pdf-engine=lualatex test.md -o test.pdf
This is LuaHBTeX, Version 1.12.0 (TeX Live 2020) 
 restricted system commands enabled.
LaTeX2e <2020-10-01> patch level 2

luaotfload | load : FATAL ERROR
luaotfload | load :   × Failed to load "fontloader" module "basics-gen".
luaotfload | load :   × Error message:
luaotfload | load :     × "...dir/texmf-dist/tex/luatex/luaotfload/luaotfload-init.lua:306: system : no writeable cache path, quiting".

stack traceback:
    ...dir/texmf-dist/tex/luatex/luaotfload/luaotfload-main.lua:174: in local 'load_fontloader_module'
    ...dir/texmf-dist/tex/luatex/luaotfload/luaotfload-init.lua:308: in upvalue 'init_main'
    ...dir/texmf-dist/tex/luatex/luaotfload/luaotfload-init.lua:560: in function 'luaotfload-init.lua'
    ...dir/texmf-dist/tex/luatex/luaotfload/luaotfload-main.lua:298: in field 'main'
    [\directlua]:1: in main chunk

...dir/texmf-dist/tex/luatex/luaotfload/luaotfload-init.lua:306: system : no wr
iteable cache path, quiting
stack traceback:
    [C]: in function 'error'
    ...dir/texmf-dist/tex/luatex/luaotfload/luaotfload-init.lua:306: in function '
    ...dir/texmf-dist/tex/luatex/luaotfload/luaotfload-main.lua:177: in local 'loa
    ...dir/texmf-dist/tex/luatex/luaotfload/luaotfload-init.lua:308: in upvalue 'i
    ...dir/texmf-dist/tex/luatex/luaotfload/luaotfload-init.lua:560: in function '
    ...dir/texmf-dist/tex/luatex/luaotfload/luaotfload-main.lua:298: in field 'mai
    [\directlua]:1: in main chunk.
<everyjob> ...ring \\def\string \\encodingdefault{OT1}')end }
                                                  \let \f@encoding \encoding...

  % Options for packages loaded elsewhere

The no writeable cache path from luaotfload caused the error. I observed that if I remove the USER pptruser related settings and run everything as root, then the error is gone.

I wonder if there's a way to build a Dockerfile so that the compilation of test.md containing the font TeX Gyre Termes with LuaLaTeX PDf engine works.

1 Answer 1


The solution is incredible simple: identify the "writable cache path", and give it the write permission to everyone. In the Docker image, pandoc/latex:latest, it's /opt/texlive/texdir/texmf-var.

I resolved this issue at commit VincentTam/pandoc-mermaid-docker@d86343f0 on GitLab by appending

chmod o+w /opt/texlive/texdir/texmf-var

to the RUN command that created the user pptruser (somewhere before changing to a normal user from root).

  • 1
    I was having a similar issue and this solution was spot on. Thanks man! Nov 16, 2021 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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