Motivation
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'
root
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 imagepandoc/latex:latest
, then the container runspandoc README.md -o README.pdf
with the user and group privileges in the base system, and ends, The outputREADME.pdf
remains after the container has ended. The--rm
is included so that it's not recorded in the list of containersdocker ps
.
Background info about Docker's USER
To avoid running as root in a Docker container, one can specify the USER name
in Dockerfile
.
Question
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.
(./201113-TAM-compte-rendu.tex
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 '
os.exit'
...dir/texmf-dist/tex/luatex/luaotfload/luaotfload-main.lua:177: in local 'loa
d_fontloader_module'
...dir/texmf-dist/tex/luatex/luaotfload/luaotfload-init.lua:308: in upvalue 'i
nit_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 'mai
n'
[\directlua]:1: in main chunk.
<everyjob> ...ring \\def\string \\encodingdefault{OT1}')end }
\let \f@encoding \encoding...
l.1
% 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.
Best Answer
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 appendingto the
RUN
command that created the userpptruser
(somewhere before changing to a normal user from root).