Skip to main content Skip to docs navigation

Software containers

On this page

Software Containers

Introduction to Software Containers

Software containers, such as Apptainer (formerly known as Singularity) and Docker provide a way to encapsulate an application and its environment for consistent, portable, and reproducible execution across various computing environments. This is crucial for scientific research, ensuring that analyses remain consistent regardless of the underlying infrastructure.

Why Use Software Containers?

  • Consistency and Reproducibility: Containers ensure your analysis runs the same way, everywhere.
  • Isolation: Package your application with its dependencies to avoid conflicts.
  • Portability: Easily share your computational environment with others.

Getting Started with Containers

Apptainer is a popular choice in scientific and high-performance computing (HPC) environments due to its ability to handle container privileges. It offers secure, user-friendly containerization, making it ideal for computational biology and bioinformatics. Based on the same technology, Docker images are compatible with Apptainer and most commands function similarly.

NFDI4Microbiota recommends that researchers start out with Apptainer if you are not bound to a docker environment, because it is usually much easier and nudges you to follow the [best practices] by default.

For installation and quick start, always refer to the main documenation page from the containirazation software of choice.

Apptainer Quick Start Docker Quick Start

Example of Working with Containers

Apptainer

To start getting an idea what a container actually is, it is relevant to get some examples. A good example of a software available as a apptainer container is Virsorter2, a multi-classifier with an expert-guided approach to detect diverse DNA and RNA virus genomes.

Running VirSorter2 using Apptainer looks like:

$ apptainer build virsorter2.sif docker://jiarong/virsorter:latest

You will get a file virsorter2.sif, which is a apptainer image that can be run like a binary executable file. You can use the absolute path of this file to replace Virsorter2 in commands. Also this image has the database and dependencies included, so you can skip the download of databases and dependencies.

Docker

Similarly with Docker, the user can find an example of running BLAST here

Best Practices for Container Creation {best-practices}

When creating containers, incorporating best practices ensures efficiency, security, and reproducibility. Here’s a concise guide, drawing from broader container best practices, including insights from Google Cloud’s recommendations:

  • Use Specific Versions: Specify exact versions of base images, software, and libraries, in order to avoid breaking changes occuring when updating with the latest tag and ensures consistency across environments.

  • Minimize Layer Size: Structure your definition file to combine related commands into single layers to reduce the container size which speeds up download and deployment.

  • Clean Up: Remove unnecessary packages and clear cache in the same layer where installations occur to minimize the container’s footprint.

  • Non-root User: Run the container as a non-root user whenever possible, which enhances the security of the container, reducing the risk of privilege escalation attacks.

  • Base Image Selection: Choose a minimal base image that includes only the necessary packages and libraries for your application, to minimizes the attack surface and the container size.

  • Immutable Containers: Treat containers as immutable. For updates or changes, build a new container image. This facilitates modularity and version control while ensuring reproducibility.

  • Security Scanning: Regularly scan your containers for vulnerabilities and apply patches as needed. Keeping your containers updated is crucial for security.

  • Efficient Data Management: Store data and logs outside of containers to ensure persistence and scalability. Use volumes or bind mounts for data that needs to persist beyond the life of the container.

  • Documentation: Include a %help section in your definition file, providing users with information on how to use the container, including running the software and accessing data.

Advanced Usage

Integration with Nextflow

  • Nextflow and Containers: Simplifies complex workflows by executing each step in a container for consistency across environments.
  • Configurations: Supports managing containers through nextflow.config, streamlining execution.

Kubernetes and Containers

  • Container Orchestration: Automates deployment, scaling, and management of containerized applications, essential for microservices architecture.
  • Scalability and Management: Provides tools for load balancing, auto-scaling, and efficient resource allocation across diverse infrastructures.

Resources and Further Reading

This page is currently empty. Please consider contributing!