# linking binaries from other containers

Been thinking about this for a while, but @benmarwick ’s examples with --volumes-from convinced me to give this a try.

While there’s an obvious level of convenience in having something like LaTeX bundled into the hadleyverse container so that users can build nice pdfs, if often feels not very docker-esque to me to just throw the kitchen sink into a container. At the risk of some added complexity, we can provide LaTeX from a dedicated TeX container to a container that doesn’t have it built in, like rocker/rstudio. Check this out:

First, we run the docker container providing the texlive binaries as linked volume. Note that even after the 4 GB texlive container has been downloaded that this is slow to execute due to the volume linking flag (not really sure why that is).

docker run --name tex -v /usr/local/texlive leodido/texlive true

Once the above task is complete, we can run the rstudio container, which doesn’t have tex installed by itself, and access tex by linking:

docker run -dP --volumes-from tex \
-e PATH=\$PATH:/usr/local/texlive/2014/bin/x86_64-linux/ \
rocker/rstudio

We can now log into RStudio, create a new Rnw file and presto, RStudio discovers the tex compilers and builds us a pdf. This does make our Docker execution lines a bit long, but that’s what fig is for. (Or a good ole Makefile).

Note this requires we build texlive in a way that isolates it to it’s own path (e.g. /usr/local/texlive). The default installation with apt-get installs everything in separate locations that overlap with existing directories (like /usr/bin), which makes linking clumsy or impossible (we would need separate paths for all the components, e.g. since shared libraries aren’t found under the bin path, and we cannot link such a volume to another container without destroying everything in it’s /usr/bin, clearly not a good idea). Instead, if we use the standard texlive install script from https://www.tug.org/texlive/, this installs everything into /usr/local/texlive which is much more portable as illustrated above. Not quite sure if it’s actually a good idea to build containers this way or not.

I’ll keep shipping latex inside the hadleyverse container (has about 300 MB of texlive that covers most common usecases), but this is certainly an intruging recipe to mix and match.