# Building Images

For more information regarding building a singularity container, the [Building a Container](https://singularity.lbl.gov/docs-build-container) documentation is excellent and we recommend becoming familiar with it.

{% hint style="info" %}
Container images can take up a lot of disk space. You may want to save them in a location with a large quota and it is also a good idea to change singularity's default cache directory ( i.e`~/.singularity)`to a location that gets cleaned up regularly i.e `~/.scratch`. In order to change the chache directory, you need to set the appropiate variable in your `~/.bashrc` file. For instance:

```bash
# set SINGULARITY_CACHEDIR. Make sure directory exists!
export SINGULARITY_CACHEDIR=~/scratch/.singularity
```

{% endhint %}

## From SingularityHub

You can use the `build` command to download a container from Singularity Hub.

```bash
singularity build <finalImageName>.simg shub://<singularityHubURL>
```

The first argument (`<finalImageName>.simg`) specifies a path and name for your container. The second argument (`shub://<singularityHubURL>`) gives the Singularity Hub URI from which to download.

{% hint style="info" %}
Note, you do not actually use the `<>` when entering your path/name or url.
{% endhint %}

## From DockerHub

If you already have a desired docker container that you would like to build as a singularity image for use on OSCAR, you can build directly from dockerHub using the build command:

```bash
singularity build <finalImageName>.simg docker://<dockerHubURL>
```

This will pull the docker image from DockerHub and build it as a singularity image locally.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ccv.brown.edu/oscar/singularity-containers/building-images.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
