# Self Contained Apptainer Images

**URL:** https://discourse.julialang.org/t/self-contained-apptainer-images/133529
**Category:** General Usage
**Tags:** question
**Created:** [October 30, 2025, 12:08am UTC](https://discourse.julialang.org/t/self-contained-apptainer-images/133529 "2025-10-30T00:08:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Gavin-Rockwood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gavin-rockwood/32/219194_2.png) [@Gavin-Rockwood](https://discourse.julialang.org/u/Gavin-Rockwood)
#### Post date: [October 30, 2025, 12:08am UTC](https://discourse.julialang.org/t/self-contained-apptainer-images/133529/1 "2025-10-30T00:08:58Z")

</div>

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:

```julia-auto
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!!

---

<div class="post-metadata">

### Author: ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)
#### Post date: [October 30, 2025, 1:08pm UTC](https://discourse.julialang.org/t/self-contained-apptainer-images/133529/2 "2025-10-30T13:08:02Z")

</div>

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

```shell
docker save -o my_app.tar my_app

```

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

```shell
apptainer build my_app.sif docker-archive://my_app.tar

```

---

<div class="post-metadata">

### Author: ![Gavin-Rockwood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gavin-rockwood/32/219194_2.png) [@Gavin-Rockwood](https://discourse.julialang.org/u/Gavin-Rockwood)
#### Post date: [October 30, 2025, 5:19pm UTC](https://discourse.julialang.org/t/self-contained-apptainer-images/133529/3 "2025-10-30T17:19:27Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)
#### Post date: [October 30, 2025, 6:36pm UTC](https://discourse.julialang.org/t/self-contained-apptainer-images/133529/4 "2025-10-30T18:36:13Z")

</div>

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.
