# Hands-on #2

## Singularity configuration file

We will build a container image for LAMMPS code using CentOS as the base image. A template Singularity configuration file is shown below:

> Create/use the lammps template configuration file `lammps.cfg`

```
# Header
BootStrap: 
OSVersion: 
MirrorURL: 
Include:

# Sections
%setup

%post

%runscript
```

### Header

We will BootStrap CentOS version `7` with package manager `yum`. The `MirrorURL` for downloading CentOS is `http://mirror.centos.org/centos-%{OSVERSION}/%{OSVERSION}/os/$basearch/`. `Include: yum`.

### Sections

In this example, we will use `%setup`, `%post` and `%runscript`.

* Download and copy LAMMPS to `/opt`. Use `$SINGULARITY_ROOTFS` to access root file system in the container:

```
cd $SINGULARITY_ROOTFS/opt
wget http://lammps.sandia.gov/tars/lammps-stable.tar.gz
```

* Install development tools: `yum -y groupinstall "Development Tools"`
* Configure and compile LAMMPS

```
mkdir -p /opt/lammps
cd /opt/lammps
tar xf ../lammps-stable.tar.gz --strip-components 1

cd src
make yes-granular |& tee log.make_yes_granular
make -j serial |& tee log.make_serial
```

* Configure the container to run `lmp_serial` on execution of the container:

```
/opt/lammps/src/lmp_serial "$@"
```

## Creating the container image

* Create a container called `lammps` and modify the size to 2048 MiB.

```
singularity image.create --size 2048 ./lammps.img`
```

* Build the lammps configuration file created in the previous step.

```
sudo singularity build ./lammps.img lammps.cfg
```

> **Note** Building step requires `root` access.

## Running the container image

To execute the container

```
singularity run /local/lammps.img -i in.granregion.mixer
```


---

# 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://kks32-courses.gitbook.io/hpc-containers/singularity/building-a-container-configuration-file/hands-on-2.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.
