Using containers (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.
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.
Using the CompNeuro container image
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.
The container image can be obtained from the Fedora Container Registry.
podman pull registry.fedoraproject.org/compneuro
It can then be used interactively:
podman run -it compneuro:latest /bin/bash
# terminal in the container
[root@95b9db71272f /]#
Using the Fedora release containers interactively
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.
First, we pull the base Fedora container image:
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
We then run the image interactively.
podman run -it fedora:latest /bin/bash
# terminal in the container
[root@95b9db71272f /]#
This gives us a container that we can work with interactively. We can install a package here as we would on a Fedora installation, for example:
[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'
In [3]:
Creating container images
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()
Our simple Containerfile looks like this:
FROM fedora:33 as fedora-33
# Install the required packages, in this case: NEST
RUN sudo dnf install python3-nest -y
COPY nest-test.py .
# Default command to run
CMD ["python", "nest-test.py"]
We can then build our container image:
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
When run, it runs our simple script:
$ 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.
In a similar way, any package from the Fedora repositories can be used in containers using dnf
(not just NeuroFedora packages).
Additionally, we can also include software using pip
and other package managers, just as we would on a normal system.
Want to help? Learn how to contribute to Fedora Docs ›