Utilizar contenedores (Docker/Podman)

Since the NeuroFedora packages are available in the Fedora repositories, they can also be used in customised containers using the Fedora base containers. The Fedora community release container images for all Fedora releases which can be obtained from standard public container image registries like Docker Hub.

These containers can be used with Docker, or Podman.

Podman is a replacement for Docker that does not require administrative access. It can be used as a drop-in replacement for Docker in a majority of cases. On a Fedora system, Podman can be installed using dnf.

sudo dnf install podman

To use Docker, please refer to the Docker documentation. Fedora also includes the Toolbox software, which allows the use of containerised command line environments. Toolbox can be installed using dnf:

$ sudo dnf install toolbox

You can learn more about it on the Fedora Silverblue documentation page.

Utilizando la imagen del contenedor CompNeuro

In parallel with the CompNeuro lab instalation media, a container image that includes the same set of software is also provided. Where the lab image is a full operating system image that can either be used "live" or installed in a virtual machine or a computer, the container image allows us to use the same software with container technologies like Podman and Docker.

La imagen de contenedor puede ser obtenidoa desde el Registro de Contenedor Fedora.

podman pull registry.fedoraproject.org/compneuro

Entonces puede ser utilizado interactivamente:

podman run -it compneuro:latest /bin/bash


# terminal dentro del contenedor
[root@95b9db71272f /]#

Utilizando interactivamente contenedores de publicación Fedora

Even though the CompNeuro container image includes a plethora of tools for computational neuroscience, any package from the Fedora repositories can be used in a container by using the base Fedora release containers. A simple example of using a Fedora container to use a NeuroFedora package is shown below. Here, we use the Fedora base container image, install the required package, and test that it works.

Primero, tomamos la imagen del contenedor Fedora base:

podman pull fedora:latest

Resolved short name "fedora" to a recorded short-name alias (origin: /etc/containers/registries.conf.d/shortnames.conf)
Trying to pull registry.fedoraproject.org/fedora:latest...
Getting image source signatures
Copying blob 8fde7942e775 [--------------------------------------] 0.0b / 0.0b
Copying config 79fd58dc76 done
Writing manifest to image destination
Storing signatures
79fd58dc76113dac76a120f22cadecc3b2d1794b414f90ea368cf66096700053

Entonces ejecutamos la imagen interactivamente.

podman run -it fedora:latest /bin/bash


# terminal dentro del contenedor
[root@95b9db71272f /]#

Esto nos proporciona un contenedor que podemos funcionar con interactividad. Podemos instalar un paquete aquí como pudimos en una instalación Fedora, por ejemplo:

[root@95b9db71272f /]# sudo dnf install python3-nest

Last metadata expiration check: 0:06:14 ago on Wed Jan  6 10:41:28 2021.
Dependencies resolved.
================================================================================
 Package                     Arch   Version                       Repo     Size
 ================================================================================
 Installing:
  python3-nest                x86_64 2.20.1-5.fc33                 updates 518 k
  Installing dependencies:
....
....
Complete!

We can then run commands normally:

[root@95b9db71272f /]# ipython
Python 3.9.0 (default, Oct  6 2020, 00:00:00)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.18.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import nest
[INFO] [2021.1.6 11:10:43 /builddir/build/BUILD/nest-simulator-2.20.1/nest-simulator-2.20.1/nestkernel/rng_manager.cpp:217 @ Network::create_rngs_] : Creating default RNGs
[INFO] [2021.1.6 11:10:43 /builddir/build/BUILD/nest-simulator-2.20.1/nest-simulator-2.20.1/nestkernel/rng_manager.cpp:260 @ Network::create_grng_] : Creating new default global RNG

Jan 06 11:10:43 CopyFile [Error]:
    Could not open source file.
Error in nest resource file: /BadIO in CopyFile_

              -- N E S T --
  Copyright (C) 2004 The NEST Initiative

 Version: nest-2.20.1
 Built: Aug 10 2020 00:00:00

 This program is provided AS IS and comes with
 NO WARRANTY. See the file LICENSE for details.

 Problems or suggestions?
   Visit https://www.nest-simulator.org

 Type 'nest.help()' to find out more about NEST.


In [2]: nest.version()
Out[2]: 'NEST nest-2.20.1'

En [3]:

Crear imágenes de contenedor

While working interactively is quite useful, it is even more useful to create container images with specific sets of packages that can then be used and re-used regularly. For reproducible research, for example, a container image that includes all the necessary software and sources for the model, its simulation, and the analysis of the generated data is most useful.

A container image can be created using a standard Containerfile (Dockerfile for Docker). The complete reference for the Containerfile/Dockerfile can be found here.

Let us create an example container that runs this short code-snippet.

#!/usr/bin/env python3
# example Python source file
# saved in the current directory as nest-test.py
import nest

nest.version()

Nuestro simple Containerfile parece como esto:

FROM fedora:33 como fedora-33

# Instala los paquetes requeridos, en este caso: NEST
RUN sudo dnf install python3-nest -y

COPY nest-test.py .

# Instrucción por defecto para ejecutar
CMD ["python", "nest-test.py"]

Entonces podemos construir mientra imagen del contenedor:

ls
Containerfile  nest-test.py

podman build -f Containerfile  -t neurofedora/nest-test

STEP 1: FROM fedora:33 AS fedora-33
STEP 2: RUN sudo dnf install python3-nest -y
Fedora 33 openh264 (From Cisco) - x86_64        1.9 kB/s | 2.5 kB     00:01
....
Complete!
--> 2efea29a8db
STEP 3: COPY nest-test.py .
--> b23a5c6f90d
STEP 4: CMD ["python3", "nest-test.py"]
STEP 5: COMMIT neurofedora/nest-test
--> da9240e572b
da9240e572b4c08ac010001cbc15cb81ae879c63dca70afa4b3e6f313254b218

Our image is now ready to use:

$ podman image list
REPOSITORY                         TAG              IMAGE ID      CREATED         SIZE
localhost/neurofedora/nest-test    latest           da9240e572b4  17 seconds ago  911 MB

Cuando ejecuta, ejecute nuestro guion:

$ podman run neurofedora/nest-test
[INFO] [2021.1.6 11:36:36 /builddir/build/BUILD/nest-simulator-2.20.1/nest-simulator-2.20.1/nestkernel/rng_manager.cpp:217 @ Network::create_rngs_] : Creating default RNGs
[INFO] [2021.1.6 11:36:36 /builddir/build/BUILD/nest-simulator-2.20.1/nest-simulator-2.20.1/nestkernel/rng_manager.cpp:260 @ Network::create_grng_] : Creating new default global RNG

Jan 06 11:36:36 CopyFile [Error]:
    Could not open source file.
Error in nest resource file: /BadIO in CopyFile_

              -- N E S T --
  Copyright (C) 2004 The NEST Initiative

 Version: nest-2.20.1
 Built: Aug 10 2020 00:00:00

 This program is provided AS IS and comes with
 NO WARRANTY. See the file LICENSE for details.

 Problems or suggestions?
   Visit https://www.nest-simulator.org

 Type 'nest.help()' to find out more about NEST.

En una manera similar, cualquier paquete desde los repos de Fedora pueden ser utilizados en contenedores utilizando dnf (no tan solo paquetes NeuroFedora). Adicionalmente, además podemos incluir software utilizando pip y otros gestores de paquete, tan solo como pudimos en un sistema usual.