Self Contained Apptainer Images

I have been trying to get a self contained apptainer image, where all the packages are saved within a directory within the container (such as /usr/local/julia/) instead of a directory on the host (usually /.julia) in order to avoid conflicts and keep my code fully contained. The .def file I am using is:

Bootstrap: docker
From: julia:1.12.1

%post
    export JULIA_DEPOT_PATH="/usr/local/julia"
    export PATH="/usr/local/julia:${PATH}"

%environment
    export JULIA_DEPOT_PATH="/usr/local/julia"
    export JULIA_HISTORY="/usr/local/julia/julia_history"

Building this as a sandbox (apptainer build --sandbox test_sb test.def) and going into the shell in writable mode (apptainer shell --writable test_sb) should, by my understanding, allow me to then run julia and then add packages which will then be saved to the new JULIA_DEPOT_PATH. However, when I run using Pkg it fails to compile. Some packages, like LinearAlgebra load just fine.

I assume I am going about this the wrong way or at the very least I am missing something important! Is what I am trying even feasible with Apptainer and if so what bits am I missing?

Thanks in advance!!

Can’t answer directly, but I’ve had no problem first building Docker images locally and then converting them to apptainer images. After I build the Docker image locally, I run

docker save -o my_app.tar my_app

This saves the image into an archive, my_app.tar. Then I convert to Apptainer:

apptainer build my_app.sif docker-archive://my_app.tar
1 Like

I was thinking about giving up on apptainer and going this route! However, this needs to be run on the cluster and the .sif images are a bit big (~500mb). I was hoping to be able to build them on the cluster. This might be the way to go though.

What I do is produce the Docker archive my_app.tar on my laptop, then use rsync or scp to transfer the file to the cluster, where I run the second command to convert it to a .sif image. My tar file is of several GB, and the final .sif file is about 750 MB.