106 lines
3.0 KiB
TeX
106 lines
3.0 KiB
TeX
% !TeX root = main.tex
|
|||
|
|
% This is an included chapter. Compile the top-level main.tex for the full report.
|
||
|
|
\chapter{LaTeX Docker}
|
||
|
|
\ChapterLabel{LatexDocker}
|
||
|
|
\index{Docker!LaTeX container}
|
||
|
|
\index{LaTeX!Docker compilation}
|
||
|
|
\index{TeX Live}
|
||
|
|
|
||
|
|
\section{Purpose and Design}
|
||
|
|
|
||
|
|
Assignment 3 Step 4 requires a Docker container that compiles a simple LaTeX
|
||
|
|
document with TeX Live, which is the TeX distribution used by Overleaf. The
|
||
|
|
project separates the build environment from the host computer: the Docker
|
||
|
|
image installs the required TeX Live package, copies the source document into
|
||
|
|
the image, and runs \texttt{pdflatex}. A bind mount returns the generated PDF
|
||
|
|
and supporting files to an \texttt{output} directory on the host.
|
||
|
|
|
||
|
|
The project has the following structure:
|
||
|
|
|
||
|
|
\begin{minted}{text}
|
||
|
|
latex-docker/
|
||
|
|
|-- Dockerfile
|
||
|
|
|-- .dockerignore
|
||
|
|
|-- sample-source.txt
|
||
|
|
`-- output/
|
||
|
|
\end{minted}
|
||
|
|
|
||
|
|
\section{Sample LaTeX Document}
|
||
|
|
|
||
|
|
The container compiles the following small source document. It uses only the
|
||
|
|
base LaTeX packages installed in the image.
|
||
|
|
|
||
|
|
\inputminted{latex}{latex-docker/sample-source.txt}
|
||
|
|
|
||
|
|
\section{Dockerfile}
|
||
|
|
|
||
|
|
The image uses a small Debian base and installs
|
||
|
|
\texttt{texlive-latex-base} together with the recommended fonts needed by the
|
||
|
|
sample document. Removing the APT package lists keeps the resulting image
|
||
|
|
smaller.
|
||
|
|
|
||
|
|
\begin{minted}{dockerfile}
|
||
|
|
FROM debian:bookworm-slim
|
||
|
|
|
||
|
|
RUN apt-get update \
|
||
|
|
&& apt-get install -y --no-install-recommends \
|
||
|
|
texlive-latex-base \
|
||
|
|
lmodern \
|
||
|
|
&& rm -rf /var/lib/apt/lists/*
|
||
|
|
|
||
|
|
WORKDIR /workspace
|
||
|
|
COPY sample-source.txt .
|
||
|
|
|
||
|
|
CMD ["pdflatex", "-interaction=nonstopmode", \
|
||
|
|
"-halt-on-error", "sample-source.txt"]
|
||
|
|
\end{minted}
|
||
|
|
|
||
|
|
The Docker build context excludes generated and editor-specific files.
|
||
|
|
|
||
|
|
\begin{minted}{text}
|
||
|
|
output/
|
||
|
|
*.aux
|
||
|
|
*.log
|
||
|
|
*.pdf
|
||
|
|
.git
|
||
|
|
.DS_Store
|
||
|
|
\end{minted}
|
||
|
|
|
||
|
|
\section{Build and Run Procedure}
|
||
|
|
|
||
|
|
From the \texttt{latex-docker} directory, the output directory is created and
|
||
|
|
the Docker image is built with the tag \texttt{latex-compiler}.
|
||
|
|
|
||
|
|
\begin{minted}{bash}
|
||
|
|
cd latex-docker
|
||
|
|
mkdir -p output
|
||
|
|
sudo docker build -t latex-compiler .
|
||
|
|
\end{minted}
|
||
|
|
|
||
|
|
The container is then run with the host output directory mounted at
|
||
|
|
\texttt{/workspace/output}. The command overrides the default container command
|
||
|
|
so that all generated files are written to the mounted location. The container
|
||
|
|
is removed automatically after compilation.
|
||
|
|
|
||
|
|
\begin{minted}{bash}
|
||
|
|
sudo docker run --rm \
|
||
|
|
-v "$(pwd)/output:/workspace/output" \
|
||
|
|
latex-compiler \
|
||
|
|
pdflatex -interaction=nonstopmode -halt-on-error \
|
||
|
|
-output-directory=/workspace/output sample-source.txt
|
||
|
|
\end{minted}
|
||
|
|
|
||
|
|
\section{Verification}
|
||
|
|
|
||
|
|
The following commands verify that the container exited successfully and that
|
||
|
|
the expected PDF was written to the host.
|
||
|
|
|
||
|
|
\begin{minted}{bash}
|
||
|
|
ls -lh output/sample-source.pdf
|
||
|
|
file output/sample-source.pdf
|
||
|
|
\end{minted}
|
||
|
|
|
||
|
|
The expected result is a valid PDF named \texttt{sample-source.pdf}. Because the build
|
||
|
|
environment is encoded in the Dockerfile, the same source and image definition
|
||
|
|
can be used on another Docker host to obtain a consistent compilation workflow.
|