Skip to content

Commit 1053672

Browse files
committed
updating environment section
1 parent 2368b11 commit 1053672

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

pages/docs/user-docs/docs-recipes.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,12 @@ You'll notice some other labels that are captured automatically from the build p
202202

203203

204204
#### %environment
205-
As of Singularity 2.3, you can add environment variables to be sourced when the container is used in the `%environment` section. The entire section is written to a file that gets sourced, so you should generally use the same conventions that you might use in a `bashrc` or `profile`.
205+
As of Singularity 2.3, you can add environment variables to your Singularity Recipe in a section called `%environment`. Keep in mind that these environment variables are sourced at runtime and *not* at build time. This means that if you need the same variables during build time, you should also define them in your `%post` section. Specifically:
206+
207+
- **during build**: the `%environment` section is written to a file in the container's metadata folder. This file is not sourced.
208+
- **during runtime**: the file written to the container's metadata folder is sourced.
209+
210+
Since the file is ultimately sourced, you should generally use the same conventions that you might use in a `bashrc` or `profile`. In the example below, the variables `VADER` `LUKE` and `SOLO` would not be available during build, but when the container is finished and run:
206211

207212
```
208213
Bootstrap: docker
@@ -230,7 +235,7 @@ Version v1.0
230235
export VADER LUKE SOLO
231236
```
232237

233-
You can easily see environment variables also with inspect:
238+
For the rationale behind this approach and why we do not source the `%environment` section at build time, refer to <a href="https://github.com/singularityware/singularity/issues/1053" target="_blank">this issue</a>. When the container is finished, you can easily see environment variables also with inspect, and this is done by showing the file produced above:
234239

235240
```
236241
$ singularity inspect -e roar.simg # Custom environment shell code should follow

0 commit comments

Comments
 (0)