ANAKIN: Is it possible to learn this power? Star Wars: Revenge of the Sith |
This tutorial is about working with IMAS in an isolated environment (containers), which you can instantiate anytime, copy and reuse with little effort on different machines. After this tutorial you will gain knowledge of:
Virtualization is a process of simulating some logical resources (CPU, memory, storage). Usually, this term refers to running whole operating systems (often multiple at once) on the same set of physical resources. This provides two major benefits. First of all, the computing/storage power of the physical resources is usually better utilized by multiple workloads coming from different virtual operating systems. Second, virtualization provides the benefit of isolating whole environment from the host and from other guest systems. This elevates security and makes it easier to maintain quality services running in dedicated environments. Furthermore, as virtualization becomes more and more popular, standardized approaches begin to appear, which improves interoperability and ease of use.
A related technique of deploying isolated environments is called containerization. In this approach, the host operating system encapsulates an application and its own environment. Note, that containers do not emulate the full operating system stack with hardware drivers, but rather it reuses what host OS provides. This makes containers much more lightweight, quick to instantiate and introducing less overhead. At the same time, the benefits of virtualization are still there. The same physical resources can host multiple running containers, each being isolated from the rest with their own dedicated environments and settings.
Docker is the most popular project related with containerization. It established technical details of container image format, of the Dockerfile (a recipe on how to create an image) and of the Docker tool to manage images and running containers. It also made it possible to arrange multiple containers in a well-defined network to cooperate to reach a common goal. Currently, Docker has several alternatives, but majority of them support Docker formats and mimic Docker tool behavior as it became a de facto standard.
Please follow the steps from official documentation:
All running containers start from some base image. You can find lots of open source images at Docker Hub including basic OSes (ubuntu, centos), popular database engines (postgres, mysql) and others.
docker pull <image-name>
docker images
docker rmi <image-name>
docker run <image-name> <command>
docker ps
docker cp <file-1> <file-2>
docker exec <container-id> <command>
docker rm <container-id>
Each command supports additional flags passed along the main arguments. Please make sure to check The most often used flags are:
|
/etc/os-release
with some information about the platformdocker run <image-name> cat /etc/os-release
for a few different image names: ubuntu, debian, postgres, mysql, alpine
ubuntu:xenial, ubuntu:bionic, centos:7, centos:8
docker run -it ubuntu /bin/bash
apt update
fortune
and cowsay
: apt install -y fortune cowsay
/usr/games/cowsay $(/usr/games/fortune)
mkdir /tmp/docker-exercise
echo '<img src="https://picsum.photos/200"/>' > /tmp/docker-exercise/index.html
--publish
flag to forward network traffic from host's 8080 port to container's 80 port: docker run --volume /tmp/docker-exercise/:/usr/local/apache2/htdocs/ --publish 8080:80 httpd:2.4
Note, that flag |
Singularity is an alternative way to run containers, often with the purpose of scientific computing on HPCs. Whereas Docker excels at microservices i.e. small and single-application containers with a single TCP port open to the public, Singularity aims to provide reproducible results embedded in a container image available to the public. Because of that, several details such as image tagging and even image format differ between Singularity and Docker (with a conversion tool available). Additionally, Singularity has a different mode of operation which does not require superuser privileges, therefore it is more suitable to be installed on HPCs. It also has a native support for MPI and GPGPU calculations.
Singularity is installed on Marconi HPC and available there after executing: module load singularity
Instructions to install Singularity are available in the documentation.
singularity search ubuntu
singularity pull library://library/default/ubuntu
ls -l ubuntu_latest.sif
./ubuntu_latest.sif
whoami
and id
$HOME
directory from the container: ls -l
cat /etc/os-release
Note that while you are inside container (
while
|
uDocker was created in H2020 project INDIGO-DataCloud. It uses Docker images natively, but provides a userspace tool to run and manage containers. Because it does not require superuser privileges, it is also a good fit as a container tool to be used in HPCs. uDocker also supports MPI calculations and provides ways to access host's GPU.
uDocker is contained in a single Python file making it easy to deploy in distributed systems. To install it on Gateway execute:
export WORK=/pfs/work/$USER mkdir -p ~/.local/bin ${SCRATCH} ln -s ${WORK}/udocker ~/.udocker wget https://github.com/indigo-dc/udocker/releases/download/1.3.4/udocker-1.3.4.tar.gz tar zxvf udocker-1.3.4.tar.gz -C ${WORK}/ chmod u+rx ${WORK}/udocker #test udocker exec ${WORK}/udocker/udocker --help #install ${WORK}/udocker/udocker install |
The same steps can be repeated on other machines, including HPC or your local computer. Just change WORK and SCRATCH variables in the first two lines. Note, that SCRATCH will be used during import of new images and WORK will be used to store images and files on all running containers. Choose them wisely to accommodate possibly big amount of data. |
If
|
${WORK}/udocker/udocker pull ubuntu
${WORK}/udocker/udocker
images
${WORK}/udocker/udocker
create --name=udocker-ubuntu ubuntu
${WORK}/udocker/udocker
ps
${WORK}/udocker/udocker
run udocker-ubuntu /bin/bash
whoami
cat /etc/os-release
exit
cat /etc/os-release
${WORK}/udocker/udocker
rm udocker-ubuntu
As in case of
while
|
IMAS environment is available as a Docker image. There are two flavors of the image: batch and GUI. Each image has a predefined environment, so unlike on Gateway, you do not need to load any modules or call imasdb
to get started. Both images them are exported as archives and made available on the Gateway.
To load the images, please run:
${WORK}/udocker/udocker load -i ~g2tomz/public/imas-fc2k-latest.tar.xz ${WORK}/udocker/udocker load -i ~g2tomz/public/imas-gui-latest.tar.xz |
Each step takes a bit longer than 1 minute without any progress indication, so please wait until it is finished. |
${WORK}/udocker/udocker
images
${WORK}/udocker/udocker
create --name=imas imas/fc2k:3.24.0-4.2.0-2.5p4-3.0.5-4.6.5
${WORK}/udocker/udocker
run imas /bin/bash
Prepare and run a Python script which will create IDS pf_active in shot 1 and run 1:
cat << EOF > put_pf.py import imas if __name__ == '__main__': ids = imas.ids(1, 1, 1, 1) ids.create_env('imas', 'test', '3') ids.pf_active.ids_properties.comment = 'Test data' ids.pf_active.ids_properties.homogeneous_time = 0 ids.pf_active.coil.resize(2) ids.pf_active.coil[0].name = 'COIL 1A' ids.pf_active.coil[1].name = 'COIL 2B' number = 10 ids.pf_active.coil[0].current.data.resize(number) ids.pf_active.coil[0].current.time.resize(number) for i in range(number): ids.pf_active.coil[0].current.data[i] = 2 * i ids.pf_active.coil[0].current.time[i] = i number = number + 2 ids.pf_active.coil[1].current.data.resize(number) ids.pf_active.coil[1].current.time.resize(number) for i in range(number): ids.pf_active.coil[1].current.data[i] = 2 * i + 10 ids.pf_active.coil[1].current.time[i] = i + number ids.pf_active.put() EOF python put_pf.py |
~/.udocker
. Copy the generated pulsefile directly into your Gateway's collection of pulsefiles:cp ${WORK}/udocker/containers/imas/ROOT/home/imas/public/imasdb/test/3/0/ids_10001.* ~/public/imasdb/test/3/0/
idsdump $USER test 3 1 1 pf_active
${WORK}/udocker/
udocker create --name=imas-gui imas/gui:3.24.0-4.2.0-2.5p4-3.0.5-4.6.5
${WORK}/udocker/udocker
run --publish 15901:5901 imas-gui
localhost:15901
and use imas
as the password: vncviewer localhost:15901
${WORK}/udocker/udocker
run imas-gui /bin/bash
cp ${WORK}/udocker/containers/imas/ROOT/home/imas/public/imasdb/test/3/0/ids_10001.* ${WORK}/udocker/containers/imas-gui/ROOT/home/imas/public/imasdb/test/3/0/