Install apptainer in the Linux

To build and execute an apptainer container, Apptainer needs to be installed.

For Ubuntu Linux above 20.04,

$ sudo apt update
$ sudo apt install -y software-properties-common
$ sudo add-apt-repository -y ppa:apptainer/ppa
$ sudo apt update
$ sudo apt install -y apptainer

(Note) in the Ubuntu 18.04 or below, you need to compile apptainer manually by yourself according to the instruction in the https://github.com/apptainer/apptainer/blob/main/INSTALL.md

For RHEL and CentOS

$ sudo yum install -y epel-release
$ sudo yum install -y apptainer

Build Ubuntu 22.04 Apptainer Container

Build the ubuntu 22.04 server container using the docker image. Following command creates a SIF file for the container.

$ apptainer build --sandbox ubuntu22.04-base.sif docker://ubuntu

Login to the container shell using apptainer shell command with --writable option to update and install applications in the container. And --fakeroot is root previlige in the container.

$ apptainer shell --writable --fakeroot ubuntu22.04.sif

In the Apptainer container, Ubuntu linux commands works like Ubuntu native OS. Apptainer> is the default prompt in the continer.

Apptainer> cat /etc/os-release

PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

In the container, update and install necessary packages.

Apptainer> apt -y update
Apptainer> apt-get -y install net-tools iputils-ping wget git vim build-essential flex libz-dev csh rsync

Change shell prompt. Append default prompt and locale setting in the /.singularity.d/env/99-base.sh
99-base.sh file that is run at the container start time.

Apptainer> vi  /.singularity.d/env/99-base.sh

# default promt and Locale in the container
export PS1='[Apptainer] u@h:W$ '
export LANG="C"
export LC_ALL="C"

Install Desktop in the container

To use a GUI environment install MATE desktop in the container. At first, copy the ubuntu22.04-base.sif to baram23.3.5-ubuntu22.04.sif to maintain the base container image.

$ cp -a ubuntu22.04-base.sif baram23.3.5-ubuntu22.04.sif

Launch the container and install MATE desktop environment

$ apptainer shell --writable --fakeroot baram23.3.5-ubuntu22.04.sif/
[apptainer] root@hostname:~$ apt-get update
[apptainer] root@hostname:~$ apt install -y mate-core mate-desktop-environment mate-notification-daemon

After installation, run mate-terminal in the container


[apptainer] root@hostname:~$ unset DBUS_SESSION_BUS_ADDRESS ; mate-terminal

The mate-terminal which is running in the container is shown on host session.

Install OpenMPI-4.1.6

Start the container image.

$ apptainer shell --writable --fakeroot baram23.3.5-ubuntu22.04.sif/

Install required packages to compile openmpi-4.1.6 in the container.

[apptainer] root@hostname:~$ apt-get -y update
[apptainer] root@hostname:~$ apt-get -y install build-essential flex zlib1g-dev libgmp-dev libmpfr-dev

Before installing the OpenMPI from source, remove default openmpi packages

[apptainer] root@hostname:~$ apt-get remove openmpi*

Download openmpi 4.1.6 source and install /opt/openmpi-4.1.6 directory

[apptainer] root@hostname:~$ wget https://download.open-mpi.org/release/open-mpi/v4.1/openmpi-4.1.6.tar.gz
[apptainer] root@hostname:~$ tar zxf openmpi-4.1.6.tar.gz
[apptainer] root@hostname:~$ rm openmpi-4.1.6.tar.gz
[apptainer] root@hostname:~$ cd openmpi-4.1.6
[apptainer] root@hostname:~$ ./configure --prefix=/opt/openmpi-4.1.6
[apptainer] root@hostname:~$ make -j 4 all
[apptainer] root@hostname:~$ make install
[apptainer] root@hostname:~$ echo 'export PATH=$PATH:/opt/openmpi-4.1.6/bin' >> /.singularity.d/env/99-base.sh

Install BARAM 23 in the container

Start mate-terminal and install BARAM 23 according to instructions in BARAM installation.

[apptainer] root@hostname:~$ unset DBUS_SESSION_BUS_ADDRESS ; mate-terminal

At first, clone the source code under /opt in the mate-terminal for all container users.

root@ubuntu20:~# apt-get -y install python3-pip 
root@ubuntu20:~# apt install -y qtcreator qtbase5-dev qt5-qmake cmake
root@ubuntu20:~# cd /opt
root@ubuntu20:opt# git clone https://github.com/nextfoam/baram.git
root@ubuntu20:opt# cd baram
root@ubuntu20:baram# pip install -r requirements.txt

Copy Solver Executables in the installation guide

root@ubuntu20:~# cd /opt/baram
root@ubuntu20:baram# wget https://d3c6e16xufx1gb.cloudfront.net/solvers_linux_v1.5_20230723.tar.xz
root@ubuntu20:baram# tar xf solvers_linux_v1.5_20230723.tar.xz
root@ubuntu20:baram# rm solvers_linux_v1.5_20230723.tar.xz

Compile daemonizer and resouce Files

root@ubuntu20:baram# gcc -o solvers/openfoam/bin/baramd misc/baramd.c
root@ubuntu20:baram# python3 convertUi.py

To run baramMesh and baramFlow, modify run scripts in the baram directory.
In the baramMesh.sh comment out the activate and change python to python3

root@ubuntu20:baram# vi /opt/baram/baramMesh.sh 

#source venv/bin/activate
python3 -m baramMesh.main

In the baramFlow.sh comment out the activate and change python to python3

root@ubuntu20:baram# vi /opt/baram/baramFlow.sh

#source venv/bin/activate
python3 -m baramMesh.main

Add the /opt/baram in the $PATH environment variables for all users

# vi  /.singularity.d/env/99-base.sh

export PATH=$PATH:/opt/baram

Run baramMesh and baramFlow in the mate-terminal

root@ubuntu20:baram# baramMesh.sh

Install Paraview and firefox

root@ubuntu20:baram # apt-get -y install paraview
root@ubuntu20:baram # apt install -y firefox

Install google chrome according to here

Run baramMesh and baramFlow in the container

you can run baramMesh or baramFlow in the container shell or in the host OS directly

  • Run application in the container shell
    Execute the apptainer container shell using apptainer shell command

    $ apptainer shell --writable baram23.3.5-ubuntu22.04.sif/
    [apptainer] username@hostname:~$ baramMesh.sh
  • Run application in the host shell
    baramMesh and baramFlow can be executed in the host shell using apptainer exec command

    $ apptainer exec --writable baram23.3.5-ubuntu22.04.sif/ /opt/baram/baramFlow.sh
  • Launch the GUI terminal in the container directly, and run baramMesh.sh or baramFlow.sh in the GUI terminal
    $ unset DBUS_SESSION_BUS_ADDRESS; apptainer exec --writable baram23.3.5-ubuntu22.04.sif/ mate-terminal
2 thoughts on “Build BARAM Apptainer image”
  1. 여기 있는대로 하면 ubuntu18.04에서는 apptainer 설치가 안되는 것 같네요. 방법은 있겠지만… 요즘은 18.04에서는 안되는게 너무 많아서 우분투를 업그레이드 하는게 나을 듯 하네요.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다