Issue
I want to run Latex within a docker container and offer it other containers as a service. Then I want to access the "service" via VS Codes Container extension. It should be something like this, Latex Mircoservice. If possible I want to use docker-compose. The advantage of this approach, would be the lower disk usage, as for now I am building for every latex project a container, which contains the full latex installation. Each container uses around ~5GB.
My current Dockerfile creates the my-latex image, which should then be used by various projects.
FROM texlive/texlive:latest
RUN apt-get update && \
apt-get -y install build-essential && \
cpan YAML::Tiny && \
cpan File::HomeDir && \
cpan Unicode::GCString
To build the image I run: docker build -t my-latex .
In my project dir I then create an docker-compose.yml, which looks the following:
services:
latex:
image: my-latex
volumes:
- ./latex:/workspace
tty: true
command: ["bash"]
Within my project dir I run docker-compose up
.
However, if I want to reopen in container I'll get an error, that the workspace does not exist, as shown below.
I have tried different approaches in the docker-compose.yml, but I could not get it working.
Maybe I am missing out on something. But as far as I am aware this problem should be solveable with docker.
Thanks in advance
Solution
latex
is not a long-running command. It will compile a LaTeX source file to the TeX DVI format, then exit. It doesn't make sense to try to run it as a long-running Compose service.
For this setup, I'd run one-off containers using docker run
, or a similar API-based invocation
docker run \
--rm \
-v "$PWD/latex:/workspace" \
-w /workspace \
my-image \
pdflatex my-document
You mention disk space as a concern. A Docker container works via a copy-on-write filesystem layer on top of its image. So long as you don't try to overwrite any of the TeX filesystem content, every container will share it with the underlying image. While diagnostics like docker ps
might apparently show a large container, checking with tools like df
won't show any more disk space being used.
Answered By - David Maze Answer Checked By - Mildred Charles (WPSolving Admin)