...
Markdown |
---|
## Introduction - Docker is a tool which allows to start containers i.e. lightweight lightweight, isolated environments (OS, libraries, configurations) - You can install Docker for Mac, Windows or Linux: [documentation](https://docs.docker.com/get-docker/) - To work with a container you need an image to start from - Images can be found in public or private repositories: - Base operating systems e.g. [Ubuntu](https://hub.docker.com/_/ubuntu) or [CentOS](https://hub.docker.com/_/centos) - Ready-to-start interpreters e.g. [Python](https://hub.docker.com/_/python) or [PHP](https://hub.docker.com/_/php) - Database management systems e.g. [MySQL](https://hub.docker.com/_/mysql) or [PostgreSQL](https://hub.docker.com/_/postgres) - A container executes one or more processes in its isolated environment - The process might be a daemon e.g. Apache Apache HTTP Server or it can be an interactive terminal - Dockerization advantages: - Quick prototyping and testing - For example, you can easily spawn multiple versions of PostgreSQL and test your SQL queries against them - Better dissemination - The product owner can share a Docker image and anyone interested can use it straight away - Enhanced security - A container is isolated and runs a limited number of processes - Even if it gets hacked, the rest of the system remains unharmed - Easier maintenance - The images are usually built in an automatic way via CI/CD pipelines or regularly scheduled jobs - No matter how complex the environment is, once the image recipe is created all interested users can instantiate containers at will ## IMAS Docker - The IMAS environment is available under a few flavors - The most important is `imas/ual`, which contains Data Dictionary and Access Layer - The images are available in a private Docker registry <https://rhus-71gitlab.maneufus.poznanpsnc.pl>, which requires logging in first: ``` sh docker login rhus-71gitlab.maneufus.poznanpsnc.pl :5050 ``` ### Interactive session - To pull the image: ``` sh docker pull rhus-71gitlab.maneufus.poznanpsnc.pl:5050/containerization/imas/imas-installer/rockylinux8.6/ual :latest ``` - To tag the image with shorter name: ``` sh docker tag rhus-71gitlab.maneufus.poznanpsnc.pl:5050/containerization/imas/imas-installer/rockylinux8.6/ual:latest imas/ual ``` - To begin an interactive session: ``` sh docker run -it imas/ual ``` - `-it` stands for `--interactive` and `--tty`, which allows to establish the session ### Running codes in the container - A collection of simple IMAS codes to start with can be found here: <https://github.com/tzokgitlab.eufus.psnc.pl/imas/imas-hello-world> - The examples cover C++, Fortran, Java and Python - All codes create the `summary` IDS in `shot=1` and `run=1`, each with a different value in the `comment` field - There is a helper Python script `python/read.py` which allows to verify correctness of those codes #### C++ Source code of `cpp/hello.cpp`: ``` cpp #include <UALClasses.h> #include <pwd.h> #include <unistd.h> int main() { uid_t uid = geteuid(); struct passwd *pw = getpwuid(uid); IdsNs::IDS ids(1, 1, 0, 0); ids.createEnv(pw->pw_name, "test", "3"); ids._summary.ids_properties.comment = "Hello World from C++"; ids._summary.ids_properties.homogeneous_time = 1; ids._summary.time.resize(1); ids._summary.time(0) = 0.1; ids._summary.put(); ids.close(); return 0; } ``` |
Markdown |
---|
#### Fortran
Source code:
``` fortran
program test
use ids_routines
character(32) :: login
integer :: pulsectx
integer :: status
type(ids_summary) :: summary
call getlog(login)
call ual_begin_pulse_action(MDSPLUS_BACKEND, 1, 1, login, 'test', '3', pulsectx)
call ual_open_pulse(pulsectx, FORCE_CREATE_PULSE, '', status);
allocate(summary%ids_properties%comment(1))
summary%ids_properties%comment(1) = 'Hello World from Fortran'
summary%ids_properties%homogeneous_time = 1;
allocate(summary%time(1))
summary%time(1) = 0.1
call ids_put(pulsectx, "summary", summary)
call ids_deallocate(summary)
call ual_close_pulse(pulsectx, FORCE_CREATE_PULSE, '', status)
end program test
``` |
Markdown |
---|
#### Java
Source code:
``` java
package pl.psnc.imas;
import imasjava.imas;
import imasjava.imas.summary;
import imasjava.UALException;
import imasjava.Vect1DDouble;
public class HelloWorld {
public static void main(String[] args) throws UALException {
int pulseCtx = imas.createEnv(1, 1, System.getProperty("user.name"), "test", "3");
summary s = new summary();
s.ids_properties.comment = "Hello World from Java";
s.ids_properties.homogeneous_time = 1;
s.time = new Vect1DDouble(new double[] { 0.1 });
imas.summary.put(pulseCtx, "summary", s);
}
}
``` |
Markdown |
---|
#### Python
Source code:
``` python
#! /usr/bin/env python
import os
import pwd
import imas
if __name__ == '__main__':
uid = os.getuid()
pw = pwd.getpwuid(uid)
pulsefile = imas.ids(1, 1)
pulsefile.create_env(pw.pw_name, 'test', '3')
summary = pulsefile.summary
summary.ids_properties.comment = 'Hello World from Python'
summary.ids_properties.homogeneous_time = 1
summary.time.resize(1)
summary.time[0] = 0.1
summary.put()
pulsefile.close()
``` |
Markdown |
---|
### Data transfer
- There are two approaches to transfer data to and from the container
- The first one uses `docker cp` which can copy files from the host to
the container or vice versa
- Create the container with a meaningful name using
`--name <NAME>` parameter added to `docker run` command:
``` sh
docker run -it --name demo imas/ual
```
- To copy one file at a time:
``` sh
docker cp ids_10001.characteristics demo:/root/public/imasdb/test/3/0/
docker cp ids_10001.datafile demo:/root/public/imasdb/test/3/0/
docker cp ids_10001.tree demo:/root/public/imasdb/test/3/0/
```
- To copy more files/directories at once:
``` sh
tar c ids_10001.* | docker cp - demo:/root/public/imasdb/test/3/0/
``` |
Markdown |
---|
- The second approach uses volumes i.e., a mapping of a local
directory (which must be provided as an absolute path) to a
container path
- Start the container with
`--volume <LOCAL_PATH>:<CONTAINER_PATH>` parameter added to
`docker run` command
``` sh
docker run -it --volume $(pwd):/root/public/imasdb/test/3/0 imas/ual
```
- The volume approach is recommended as it allows a seamless two-way
transfer between the host and the container |