Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pages/docs/user-docs/docs-bootstrap-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ You can add environment variables to be sourced when the container is used in th
export VADER LUKE SOLO
```

You can also add environment variables to your container in the `%post` section (see below) using the following syntax:

```
%post
echo 'export JAWA_SEZ=wutini' >>$SINGULARITY_ENVIRONMENT
```

Variables added to your container using the `$SINGULARITY_ENVIRONMENT` syntax take precedence over those added in the `%environment` section.

See <a href="/docs-environment-metadata">Environment and Metadata</a> for more information about the `%labels` and `%environment` sections.


Expand Down
11 changes: 11 additions & 0 deletions pages/docs/user-docs/docs-bootstrap.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ Beginning with Singularity v2.3 you can set up your environment using the `%envi
export PATH=/opt/good/stuff:$PATH
```

In older versions of Singularity you could set up your container's environment by adding text to a file called `/environment`. This method is now deprecated. If you need to add environment variables to your container during the `%post` section (perhaps because you will not know the values of some variables until some installation steps have completed). You can do so with the following syntax:

```
%post
echo 'export PATH=/opt/good/stuff:$PATH' >>$SINGULARITY_ENVIRONMENT
```

Text in the `%environment` section will be appended to a file called `/.singularity.d/env/90-environment.sh`. Text redirected to the `$SINGULARITY_ENVIRONMENT` variable will added to a file called `/.singularity.d/env/91-environment.sh`. At runtime, scripts in `/.singularity/env` are sourced in order.

This means that variables in `$SINGULARITY_ENVIRONMENT` take precedence over those added via `%environment

### %runscript
The `%runscript` is another scriptlet, but it does not get executed during bootstrapping. Instead it gets persisted within the container to a file called `/singularity` which is the execution driver when the container image is ***run*** (either via the `singularity run` command or via executing the container directly).

Expand Down
11 changes: 10 additions & 1 deletion pages/docs/user-docs/docs-environment-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ From: ubuntu:latest
export VARIABLE_NAME
```

If you need to add an environment variable to your container during the `%post` section, you can do so using the `$SINGULARITY_ENVIRONMENT` variable with the following syntax:

```
%post
echo 'export VARIABLE_NAME=VARIABLE_VALUE' >>$SINGULARITY_ENVIRONMENT
```

Text in the `%environment` section will be appended to the file `/.singularity.d/env/90-environment.sh` while text redirected to `$SINGULARITY_ENVIRONMENT` will end up in the file `/.singularity.d/env/91-environment.sh`. Because files in `/.singularity.d/env` are sourced in alpha-numerical order, this means that variables added using `$SINGULARITY_ENVIRONMENT` take precedence over those added via the `%environment` section.

Forget something, or need a variable defined at runtime? You can set any variable you want inside the container by prefixing it with "SINGULARITYENV_". It will be transposed automatically and the prefix will be stripped. For example, let's say we want to set the variable `HELLO` to have value `WORLD`. We can do that as follows:

```bash
Expand Down Expand Up @@ -78,7 +87,7 @@ singularity inspect dino.img
}
```

You will notice that the one label doesn't belong to the label schema, `MAINTAINER`. This was a user provided label during bootstrap. For versions earlier than 2.4, containers did not use the label schema:
You will notice that the one label doesn't belong to the label schema, `MAINTAINER`. This was a user provided label during bootstrap. Finally, for Singularity greater than version 2.4, the image build size is added as a label, `org.label-schema.build-size`, and the label schema is used, period. For versions earlier than 2.4, containers did not use the label schema, and looked like this:


```bash
Expand Down