Skill Tracer
Skills › Scientific Agent Skills › nextflow › containers.md

containers.md

96 lines · skills/nextflow/references/containers.md at 5f2bc03

Open on GitHub
1# Software Dependencies: Containers & Conda
2
3Nextflow uses a process’s declared software environment when the corresponding runtime is enabled; otherwise tools run on the host. Pin environments for reproducible analyses. Targets Nextflow 26.04.6; configurations below are illustrative, without live container/cloud execution. Sources: https://docs.seqera.io/nextflow/container , https://docs.seqera.io/nextflow/conda , https://docs.seqera.io/nextflow/wave .
4

Software Dependencies: Containers & Conda

Nextflow uses a process’s declared software environment when the corresponding runtime is enabled; otherwise tools run on the host. Pin environments for reproducible analyses. Targets Nextflow 26.04.6; configurations below are illustrative, without live container/cloud execution. Sources: https://docs.seqera.io/nextflow/container , https://docs.seqera.io/nextflow/conda , https://docs.seqera.io/nextflow/wave .

Raw lines 1 to 4
5## Choosing an engine
6
7| Engine | Use when | Enable |
8|--------|----------|--------|
9| **Docker** | Local dev / laptops / CI with root or docker group | `docker.enabled = true` |
10| **Singularity / Apptainer** | HPC clusters (no root, shared FS) — most common in academia | `singularity.enabled = true` (or `apptainer.enabled = true`) |
11| **Podman** | Rootless alternative to Docker | `podman.enabled = true` |
12| **Charliecloud / Sarus / Shifter** | Site-specific HPC runtimes | `charliecloud.enabled = true`, etc. |
13| **Conda / Mamba** | No container runtime available; quick envs | `conda.enabled = true` |
14| **Wave** | Resolve/build images from Conda/Dockerfiles for a supported executor/runtime | `wave.enabled = true` in addition to that execution setup |
16Enable one task execution environment (container runtime or Conda). Wave is an image service, not a competing runtime, and may be combined with a supported container setup. nf-core ships these as profiles, so users typically just pass `-profile docker` / `-profile singularity` / `-profile conda`.

Choosing an engine

EngineUse whenEnable
DockerLocal dev / laptops / CI with root or docker groupdocker.enabled = true
Singularity / ApptainerHPC clusters (no root, shared FS) — most common in academiasingularity.enabled = true (or apptainer.enabled = true)
PodmanRootless alternative to Dockerpodman.enabled = true
Charliecloud / Sarus / ShifterSite-specific HPC runtimescharliecloud.enabled = true, etc.
Conda / MambaNo container runtime available; quick envsconda.enabled = true
WaveResolve/build images from Conda/Dockerfiles for a supported executor/runtimewave.enabled = true in addition to that execution setup

Enable one task execution environment (container runtime or Conda). Wave is an image service, not a competing runtime, and may be combined with a supported container setup. nf-core ships these as profiles, so users typically just pass -profile docker / -profile singularity / -profile conda.

Raw lines 5 to 17
18## The container directive
20Each process declares its image; the engine config decides how it runs.
22```nextflow
23process SAMTOOLS_SORT {
24 container 'community.wave.seqera.io/library/htslib_samtools:1.24--d697cfb9dce007cd'
25 conda 'bioconda::samtools=1.24' // fallback when -profile conda is used
26 input:
27 path bam
28 output:
29 path "sorted.bam", emit: bam
30 script:
31 """
32 samtools sort -@ $task.cpus -o sorted.bam "$bam"
33 """
35```
37nf-core modules declare **both** a `container` and a `conda` line for supported profiles; architecture and runtime support still need validation. Current modules can use Seqera Community/Wave images as well as BioContainers/Galaxy depot. In nf-core modules the `conda` directive references a separate file — `conda "${moduleDir}/environment.yml"` — rather than an inline string. Biocontainers images live on `quay.io/biocontainers/...` (and `https://depot.galaxyproject.org/singularity/...` for Singularity), auto-built from Bioconda recipes.

The container directive

Each process declares its image; the engine config decides how it runs.

process SAMTOOLS_SORT {
    container 'community.wave.seqera.io/library/htslib_samtools:1.24--d697cfb9dce007cd'
    conda     'bioconda::samtools=1.24'    // fallback when -profile conda is used
    input:
    path bam
    output:
    path "sorted.bam", emit: bam
    script:
    """
    samtools sort -@ $task.cpus -o sorted.bam "$bam"
    """
}

nf-core modules declare both a container and a conda line for supported profiles; architecture and runtime support still need validation. Current modules can use Seqera Community/Wave images as well as BioContainers/Galaxy depot. In nf-core modules the conda directive references a separate file — conda "${moduleDir}/environment.yml" — rather than an inline string. Biocontainers images live on quay.io/biocontainers/... (and https://depot.galaxyproject.org/singularity/... for Singularity), auto-built from Bioconda recipes.

Raw lines 18 to 38
39## Docker
41```groovy
42docker {
43 enabled = true
44 runOptions = '-u $(id -u):$(id -g)' // avoid root-owned output files
46```

Docker

docker {
    enabled    = true
    runOptions = '-u $(id -u):$(id -g)'   // avoid root-owned output files
}
Raw lines 39 to 47
48## Singularity / Apptainer
50```groovy
51singularity {
52 enabled = true
53 autoMounts = true // auto-bind host paths
54 cacheDir = '/shared/singularity' // or set NXF_SINGULARITY_CACHEDIR
56```
58- Nextflow auto-converts Docker images to SIF on first use and caches them. On clusters, set a **shared** `cacheDir`/`NXF_SINGULARITY_CACHEDIR` so all jobs reuse pulls.
59- Bind extra paths with `runOptions = '-B /scratch'` if `autoMounts` misses them.
60- Apptainer and SingularityCE are distinct runtimes; enable the scope matching the installed executable. Both support Nextflow’s image/cache/bind workflow.

Singularity / Apptainer

singularity {
    enabled    = true
    autoMounts = true                      // auto-bind host paths
    cacheDir   = '/shared/singularity'     // or set NXF_SINGULARITY_CACHEDIR
}
  • Nextflow auto-converts Docker images to SIF on first use and caches them. On clusters, set a shared cacheDir/NXF_SINGULARITY_CACHEDIR so all jobs reuse pulls.
  • Bind extra paths with runOptions = '-B /scratch' if autoMounts misses them.
  • Apptainer and SingularityCE are distinct runtimes; enable the scope matching the installed executable. Both support Nextflow’s image/cache/bind workflow.
Raw lines 48 to 61
62## Conda / Mamba
64```groovy
65conda {
66 enabled = true
67 useMamba = true // faster solver
68 channels = 'conda-forge,bioconda' // priority order (this is the default since 26.04)
69 cacheDir = '/shared/conda_envs'
71process.conda = 'bioconda::bwa=0.7.17 bioconda::samtools=1.19'
72```
74A version-only Conda specification can resolve differently over time and does not isolate the OS. Use lockfiles/explicit package records and platform metadata; containers also need immutable digests and architecture records. Use `NXF_CONDA_CACHEDIR` to reuse built envs.

Conda / Mamba

conda {
    enabled    = true
    useMamba   = true                       // faster solver
    channels   = 'conda-forge,bioconda'     // priority order (this is the default since 26.04)
    cacheDir   = '/shared/conda_envs'
}
process.conda = 'bioconda::bwa=0.7.17 bioconda::samtools=1.19'

A version-only Conda specification can resolve differently over time and does not isolate the OS. Use lockfiles/explicit package records and platform metadata; containers also need immutable digests and architecture records. Use NXF_CONDA_CACHEDIR to reuse built envs.

Raw lines 62 to 75
76## Wave + Fusion
78**Wave** resolves/builds images and handles supported registry authentication. It does not execute the task. **Fusion** exposes supported object storage to tasks through a filesystem; requirements, credentials and costs depend on executor/service configuration. Performance improvements require measurement.
80```groovy
81wave {
82 enabled = true
83 strategy = 'conda' // build images from process conda directives
85fusion.enabled = true // pair with Wave on cloud executors
86// Supply TOWER_ACCESS_TOKEN via the environment when required; never commit tokens.
87```

Wave + Fusion

Wave resolves/builds images and handles supported registry authentication. It does not execute the task. Fusion exposes supported object storage to tasks through a filesystem; requirements, credentials and costs depend on executor/service configuration. Performance improvements require measurement.

wave {
    enabled  = true
    strategy = 'conda'           // build images from process conda directives
}
fusion.enabled = true            // pair with Wave on cloud executors
// Supply TOWER_ACCESS_TOKEN via the environment when required; never commit tokens.
Raw lines 76 to 88
89## Common gotchas
91- **Two engines enabled at once** → errors or surprising behavior. Enable one (use profiles).
92- **Root-owned outputs** with Docker → set `runOptions = '-u $(id -u):$(id -g)'`.
93- **Singularity can't see input files** → enable `autoMounts` or add `-B` binds; ensure the work dir and inputs are on bound paths.
94- **HPC pull storms / quota blowups** → set a shared `NXF_SINGULARITY_CACHEDIR` and pre-pull with `nf-core pipelines download` (see `references/running-pipelines.md`).
95- **Pinning**: always use a fully versioned image tag (and digest where possible). `latest` breaks reproducibility.
96- **Offline**: pre-stage images, engine/plugins, config, inputs and references. `NXF_OFFLINE=true` prevents project/plugin downloads; it does not disable container/task network access. Wave requires its service unless all requirements have been resolved and the offline workflow avoids service calls.

Common gotchas

  • Two engines enabled at once → errors or surprising behavior. Enable one (use profiles).
  • Root-owned outputs with Docker → set runOptions = '-u $(id -u):$(id -g)'.
  • Singularity can't see input files → enable autoMounts or add -B binds; ensure the work dir and inputs are on bound paths.
  • HPC pull storms / quota blowups → set a shared NXF_SINGULARITY_CACHEDIR and pre-pull with nf-core pipelines download (see references/running-pipelines.md).
  • Pinning: always use a fully versioned image tag (and digest where possible). latest breaks reproducibility.
  • Offline: pre-stage images, engine/plugins, config, inputs and references. NXF_OFFLINE=true prevents project/plugin downloads; it does not disable container/task network access. Wave requires its service unless all requirements have been resolved and the offline workflow avoids service calls.
Raw lines 89 to 96