Files
devops-it-manual/devopsLatexDocker.tex
T

90 lines
2.2 KiB
TeX

\chapter{LaTeX Docker}
\ChapterLabel{LatexDocker}
\index{Docker}
\index{LaTeX}
\index{TeX Live}
\section{Overview}
A Docker container was created to compile a simple LaTeX document using
TeX Live. This demonstrates how Docker can provide a consistent
environment containing the dependencies required to compile LaTeX
documents.
\section{Project Setup}
A new directory called \texttt{latex-docker} was created for the
project.
\begin{minted}[breaklines,fontsize=\small]{bash}
cd ~/ssw590
mkdir latex-docker
cd latex-docker
\end{minted}
A simple LaTeX file named \texttt{document.tex} was then created. The
document contained a title, an introduction section, and a section
describing the Docker environment.
\section{Dockerfile}
A Dockerfile was created using Ubuntu 24.04 as the base image. The
TeX Live LaTeX package was installed inside the container so that
\texttt{pdflatex} could compile the document.
\begin{minted}[breaklines,fontsize=\small]{dockerfile}
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y texlive-latex-base && \
rm -rf /var/lib/apt/lists/*
WORKDIR /data
COPY document.tex .
CMD ["pdflatex", "-interaction=nonstopmode", "document.tex"]
\end{minted}
\section{Building the Docker Image}
The Docker image was built using the following command:
\begin{minted}[breaklines,fontsize=\small]{bash}
docker build -t latex-docker .
\end{minted}
\section{Compiling the LaTeX Document}
The container was executed with the current directory mounted to
\texttt{/data}. This allowed the PDF generated inside the container
to be saved on the host machine.
\begin{minted}[breaklines,fontsize=\small]{bash}
docker run --rm -v "$(pwd):/data" latex-docker
\end{minted}
After compilation, the generated files were verified using:
\begin{minted}[breaklines,fontsize=\small]{bash}
ls
\end{minted}
The resulting directory contained:
\begin{minted}[breaklines,fontsize=\small]{text}
Dockerfile
document.aux
document.log
document.pdf
document.tex
\end{minted}
\section{Result}
The Docker container successfully compiled the LaTeX source using
TeX Live and generated \texttt{document.pdf}. This demonstrates that
the LaTeX compilation environment can be packaged and executed inside
a Docker container.