

Docker containers are widely used in bioinformatics to make analyses reproducible and portable across platforms. This post looks at the problems containers solve in practice, shows how to run and debug bioinformatics tools inside them, and covers efficient ways to build images, including with Micromamba and Pixi.
This post assumes Docker is already installed and running, and focuses on using containers for bioinformatics work.
If Docker is not yet installed, the official documentation is the place to begin:
https://docs.docker.com/get-started/get-docker/
That guide covers:
docker --versiondocker run hello-worldAfter installing Docker, verify that it works:
# Check Docker versiondocker --version# Output: Docker version 24.0.0, build 12345abc
# Run a test containerdocker run hello-world# Output: Hello from Docker! This message shows that your installation appears to be working correctly.Once Docker is installed and working, this post covers:
Before continuing, verify you have:
docker --version works)docker pull hello-world works)If not, start with https://docs.docker.com/get-started/get-docker/ and come back here afterwards.
Traditionally, bioinformatics labs installed software on shared servers or laptops with commands like:
sudo apt-get install samtools bwa python3That looks simple, but it creates reproducibility, portability, and maintenance problems:
The result is that collaboration across labs, institutions, or countries becomes fragile, and reproducing results — even on your own machine — can be a challenge.
Much of bioinformatics has moved from manual installs to containers and environment managers:
docker pull quay.io/biocontainers/samtools:1.15.1--h1170115_0In short, containers and Conda address many of the problems of manual installs, which makes reproducible collaboration more routine in bioinformatics.
One advantage of Docker is the ability to run bioinformatics tools directly, without a full installation, on your own datasets. The example below uses FastQC, a widely used quality-control tool for sequencing data.
Pull the FastQC container (only needed once):
docker pull quay.io/biocontainers/fastqc:<version># Replace <version> with the specific tag, e.g. 0.11.9--hdfd78af_1Run FastQC, mounting your data folder:
docker run --rm -v "$PWD:/data" quay.io/biocontainers/fastqc:<version> fastqc /data/my_reads.fastq--rm: remove the container automatically after it exits.-v "$PWD:/data": mount the current directory (with your FASTQ file) into the container at /data.Key benefits:
This approach works for thousands of bioinformatics containers: swap FastQC for Samtools, BWA, STAR, or other tools.
Sometimes it is useful to run tools or explore interactively inside the container. Docker makes this possible with the -it flags:
-i keeps STDIN open (interactive input)-t allocates a pseudo-terminal (TTY)Example: start an interactive shell inside the FastQC container:
docker run --rm -it -v "$PWD:/data" quay.io/biocontainers/fastqc:<version> /bin/bashNow you are inside the container shell:
fastqc /data/my_reads.fastqls /dataBenefits:
If a container is already running (perhaps as part of a pipeline or a background process), Docker lets you connect and debug interactively with docker exec:
List running containers:
docker psNote the CONTAINER ID in the output.
Start a bash shell inside the running container:
docker exec -it <CONTAINER_ID> /bin/bashYou can then inspect files, check logs, and run additional commands inside the live container.
Many containers run a specific tool as their default ENTRYPOINT; FastQC containers, for example, launch FastQC automatically. You can temporarily override the ENTRYPOINT and start a shell with:
docker run --rm -it --entrypoint /bin/bash quay.io/biocontainers/fastqc:<version>This starts an interactive shell even when the Dockerfile specifies a different default command, which is useful for debugging or exploring the container environment.
Summary:
docker exec to debug running containers.When a Nextflow pipeline runs with Docker containers, Nextflow generates and executes Docker commands for each task. Understanding these commands is useful for debugging and profiling, and for seeing exactly what a pipeline is doing.
Nextflow creates a work directory structure in which each task has its own folder containing:
.command.sh - the shell script to execute.command.run - the wrapper script that Nextflow uses to run the task.command.trace - task execution trace.exitcode - exit code of the taskDirectory structure:
work/├── ab/│ ├── abc123def456.../│ │ ├── .command.sh│ │ ├── .command.run│ │ ├── .command.trace│ │ └── ... (output files)│ └── def789ghi012.../│ └── ...└── fe/ └── 949a78b06c5fd8284aeb2f87d14f7d/ ├── .command.sh ├── .command.run └── ... (task outputs)To see the exact Docker command that Nextflow executed for a specific task:
# 1. Find your task's work directory# For example, in the pipeline output you might see:# vep (ensembl-vep:115.2) [fe/949a78b...]
# 2. Navigate to that directorycd work/fe/949a78b06c5fd8284aeb2f87d14f7d/
# 3. View the command that was executedcat .command.runHere is a complete example of how Nextflow runs a Docker container:
docker rm $NXF_BOXID &>/dev/null || truedocker stop $NXF_BOXID
docker run -i \ --cpu-shares 8192 \ --memory 14336m \ -e "NXF_TASK_WORKDIR" \ -e "NXF_DEBUG=${NXF_DEBUG:=0}" \ -v <your project working directory>:<your project working directory> \ -w "$NXF_TASK_WORKDIR" \ -u $(id -u):$(id -g) \ --name $NXF_BOXID \ community.wave.seqera.io/library/ensembl-vep:115.2--90ec797ecb088e9a \ /bin/bash <your project working directory>/work/fe/949a78b06c5fd8284aeb2f87d14f7d/.command.run nxf_traceEach component has a specific purpose:
| Component | Purpose |
|---|---|
docker run |
Start a new container |
-i |
Keep STDIN open (interactive) |
--cpu-shares 8192 |
Allocate CPU resources (set by Nextflow from cpus directive) |
--memory 14336m |
Limit memory to 14GB (set by Nextflow from memory directive) |
-e NXF_TASK_WORKDIR |
Pass Nextflow task work directory env var |
-e NXF_DEBUG=${NXF_DEBUG:=0} |
Pass debug flag |
-v /project:/project |
Mount project directory for input/output |
-w "$NXF_TASK_WORKDIR" |
Set working directory inside container |
-u $(id -u):$(id -g) |
Run as current user (file permissions) |
--name $NXF_BOXID |
Name the container (cleanup reference) |
image:tag |
Container image to use |
/bin/bash .command.run |
Execute the task script |
nxf_trace |
Nextflow tracing flag |
If a task fails in Nextflow, it can be re-run manually for debugging:
# 1. Navigate to the task work directorycd work/fe/949a78b06c5fd8284aeb2f87d14f7d/
# 2. View the task scriptcat .command.sh
# 3. View Nextflow's Docker wrappercat .command.run
# 4. Manually run the Docker command (copy from .command.run output)# and inspect what went wrongdocker run -i \ --cpu-shares 8192 \ --memory 14336m \ -e "NXF_TASK_WORKDIR" \ -v <your project working directory>:<your project working directory> \ -w "$NXF_TASK_WORKDIR" \ -u $(id -u):$(id -g) \ community.wave.seqera.io/library/ensembl-vep:115.2--90ec797ecb088e9a \ /bin/bash <your project working directory>/work/fe/949a78b06c5fd8284aeb2f87d14f7d/.command.run
# 5. Check the exit codecat .exitcode
# 6. View any error logscat .command.err # (if exists)cat .command.out # (if exists)
# 7. If you run on HPC, (e.g SLURM ), run submit jobsbatch .command.run
# 8. You can debug manually by running container interactivelydocker run -it -v $PWD:$PWD -w $PWD <your container>
# 9. Modify .command.sh then inside your container, start to debug by running command directlybash .command.sh| Feature | How Nextflow uses it |
|---|---|
| Resource limits | --cpus and --memory directives → --cpu-shares and --memory flags |
| Volume mounts | Pipeline inputs/outputs → -v flags |
| User permissions | Current user → -u $(id -u):$(id -g) |
| Work directory | Task-specific directory → -w "$NXF_TASK_WORKDIR" |
| Container cleanup | Automatic removal → docker rm commands |
| Environment variables | Pipeline configuration → -e flags |
Examining the actual Docker commands can help you:
Check resource allocation:
grep "cpu-shares\|memory" work/*/*/.command.runVerify mounted volumes:
grep "\-v" work/ab/abc123*/.command.runSee container images being used:
grep "docker run" work/*/*/.command.run | grep -oE "image:[^ ]+"Profile task execution:
# Check how long each task tookfor dir in work/*/*/*/.command.trace; do echo "Task: $(dirname $dir)" cat "$dir"donework/<task-id>/.command.run.Building efficient Docker images keeps them fast to download, run, and share.
Start with a lightweight, official base image
Install only required tools
Clean the cache and remove temporary files
rm -rf /var/lib/apt/lists/*Use multi-stage builds for large or compiled tools
FROM ubuntu:24.04RUN apt-get update && \ apt-get install -y --no-install-recommends samtools && \ apt-get clean && rm -rf /var/lib/apt/lists/*WORKDIR /dataCMD ["/bin/bash"]FROM ubuntu:24.04 AS builderRUN apt-get update && apt-get install -y build-essential wgetRUN wget https://github.com/samtools/samtools/releases/download/1.18/samtools-1.18.tar.bz2 && \ tar -xjf samtools-1.18.tar.bz2 && \ cd samtools-1.18 && \ ./configure --prefix=/usr/local && make && make install
FROM ubuntu:24.04RUN apt-get update && apt-get install -y --no-install-recommends libbz2-1.0 liblzma5 zlib1gCOPY --from=builder /usr/local/bin/samtools /usr/local/bin/WORKDIR /dataCMD ["/bin/bash"].dockerignore file to reduce the build context sizeBuilding Docker containers from Conda packages is one way to create reproducible bioinformatics environments. Micromamba is a lightweight alternative to Conda that works well inside containers.
Micromamba has a few practical advantages over traditional Conda for container builds:
mambaorg/micromamba image is about 150 MB.Instead of writing complex RUN commands with inline package specifications, use a conda.yml environment file.
conda.yml:
name: basechannels: - conda-forge - biocondadependencies: - bioconda::fastqc=0.12.1 - bioconda::samtools=1.18 - bioconda::bwa=0.7.17 - conda-forge::procps-ngDockerfile:
FROM mambaorg/micromamba:1.5.10-noble
# Copy environment fileCOPY --chown=$MAMBA_USER:$MAMBA_USER conda.yml /tmp/conda.yml
# Install packages from environment fileRUN micromamba install -y -n base -f /tmp/conda.yml \ && micromamba clean -a -y
# Export explicit lock file for reproducibilityRUN micromamba env export --name base --explicit > environment.lock \ && echo ">> CONDA_LOCK_START" \ && cat environment.lock \ && echo "<< CONDA_LOCK_END"
# Set PATHUSER rootENV PATH="$MAMBA_ROOT_PREFIX/bin:$PATH"
WORKDIR /dataCMD ["/bin/bash"]Each component in turn:
1. Base image:
FROM mambaorg/micromamba:1.5.10-noblemambaorg/micromamba includes Micromamba pre-installed1.5.10 is the version (pinned for reproducibility)noble is the Ubuntu 24.04 LTS variant2. Copy the environment file:
COPY --chown=$MAMBA_USER:$MAMBA_USER conda.yml /tmp/conda.ymlconda.yml into the container$MAMBA_USER is the non-root user set by the base image3. Install with Micromamba:
RUN micromamba install -y -n base -f /tmp/conda.yml \ && micromamba clean -a -y-y: auto-confirm installation-n base: install into the base environment-f /tmp/conda.yml: use the environment filemicromamba clean -a -y: remove cached packages, which reduces image size4. Generate a lock file (for reproducibility):
RUN micromamba env export --name base --explicit > environment.lock \ && echo ">> CONDA_LOCK_START" \ && cat environment.lock \ && echo "<< CONDA_LOCK_END"5. Set PATH and user:
USER rootENV PATH="$MAMBA_ROOT_PREFIX/bin:$PATH"USER root is required for some system monitoring (see procps-ng below)Notice conda-forge::procps-ng in the dependencies. The reason is:
dependencies: - conda-forge::procps-ngNextflow uses procps-ng tools (such as ps and top) to monitor:
Without them, Nextflow cannot track task resource usage. It is worth including in bioinformatics containers.
A fuller example with several bioinformatics tools:
conda.yml:
name: basechannels: - conda-forge - biocondadependencies: - bioconda::fastqc=0.12.1 - bioconda::samtools=1.18 - bioconda::bwa=0.7.17 - bioconda::bcftools=1.18 - bioconda::picard=3.0.0 - conda-forge::procps-ng - conda-forge::parallelDockerfile:
FROM mambaorg/micromamba:1.5.10-noble
COPY --chown=$MAMBA_USER:$MAMBA_USER conda.yml /tmp/conda.yml
RUN micromamba install -y -n base -f /tmp/conda.yml \ && micromamba install -y -n base conda-forge::procps-ng \ && micromamba env export --name base --explicit > environment.lock \ && echo ">> CONDA_LOCK_START" \ && cat environment.lock \ && echo "<< CONDA_LOCK_END" \ && micromamba clean -a -y
USER rootENV PATH="$MAMBA_ROOT_PREFIX/bin:$PATH"
WORKDIR /dataCMD ["/bin/bash"]1. Build the image:
docker build -t myregistry.com/bioinformatics/biotools:1.0 .2. Test it locally:
docker run --rm -v "$PWD:/data" myregistry.com/bioinformatics/biotools:1.0 \ fastqc /data/sample.fastq3. Push to a registry:
docker push myregistry.com/bioinformatics/biotools:1.04. Use it in Nextflow:
process FASTQC { tag "${meta.id}" label 'process_medium'
conda "${moduleDir}/environment.yml" container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? 'https://depot.galaxyproject.org/singularity/fastqc:0.12.1--hdfd78af_0' : 'biocontainers/fastqc:0.12.1--hdfd78af_0' }"
input: tuple val(meta), path(reads)
output: tuple val(meta), path("*.html"), emit: html tuple val(meta), path("*.zip") , emit: zip path "versions.yml" , emit: versions
when: task.ext.when == null || task.ext.when
script: def args = task.ext.args ?: '' def prefix = task.ext.prefix ?: "${meta.id}" // Make list of old name and new name pairs to use for renaming in the bash while loop def old_new_pairs = reads instanceof Path || reads.size() == 1 ? [[ reads, "${prefix}.${reads.extension}" ]] : reads.withIndex().collect { entry, index -> [ entry, "${prefix}_${index + 1}.${entry.extension}" ] } def rename_to = old_new_pairs*.join(' ').join(' ') def renamed_files = old_new_pairs.collect{ _old_name, new_name -> new_name }.join(' ')
// The total amount of allocated RAM by FastQC is equal to the number of threads defined (--threads) time the amount of RAM defined (--memory) // https://github.com/s-andrews/FastQC/blob/1faeea0412093224d7f6a07f777fad60a5650795/fastqc#L211-L222 // Dividing the task.memory by task.cpu allows to stick to requested amount of RAM in the label def memory_in_mb = task.memory ? task.memory.toUnit('MB') / task.cpus : null // FastQC memory value allowed range (100 - 10000) def fastqc_memory = memory_in_mb > 10000 ? 10000 : (memory_in_mb < 100 ? 100 : memory_in_mb)
""" printf "%s %s\\n" ${rename_to} | while read old_name new_name; do [ -f "\${new_name}" ] || ln -s \$old_name \$new_name done
fastqc \\ ${args} \\ --threads ${task.cpus} \\ --memory ${fastqc_memory} \\ ${renamed_files}
cat <<-END_VERSIONS > versions.yml "${task.process}": fastqc: \$( fastqc --version | sed '/FastQC v/!d; s/.*v//' ) END_VERSIONS """
stub: def prefix = task.ext.prefix ?: "${meta.id}" """ touch ${prefix}.html touch ${prefix}.zip
cat <<-END_VERSIONS > versions.yml "${task.process}": fastqc: \$( fastqc --version | sed '/FastQC v/!d; s/.*v//' ) END_VERSIONS """}| Feature | conda.yml + Micromamba | Traditional Conda Dockerfile |
|---|---|---|
| Build speed | Fast | Slow |
| Image size | Small for typical tools | Larger |
| Reproducibility | Explicit lock file | Dependency drift possible |
| Version pinning | Easy in YAML | Inline in Dockerfile |
| Readability | Clear, readable YAML | Complex RUN statements |
| Channel support | Multiple channels | Limited |
| Maintenance | Update conda.yml easily | Rebuild entire Dockerfile |
The generated environment.lock file can be saved in the project:
# Extract from build output and savedocker build . 2>&1 | grep -A 1000 "CONDA_LOCK_START" | grep -B 1000 "CONDA_LOCK_END" > environment.lockLater, the exact environment can be reproduced:
# Rebuild from locked versionsmicromamba install -y -n base --file environment.lockPixi is a newer tool that combines aspects of Conda, Mamba, and lock-file management. It is increasingly used in bioinformatics for building reproducible containers.
Why Pixi?
Example Dockerfile with Pixi:
ARG PIXI_VERSION=0.63.2ARG BASE_IMAGE=debian:bookworm-slim
FROM --platform=linux/amd64 ubuntu:24.04 AS builderARG PIXI_VERSIONRUN apt-get update && apt-get install -y curlRUN curl -Ls \ "https://github.com/prefix-dev/pixi/releases/download/v${PIXI_VERSION}/pixi-$(uname -m)-unknown-linux-musl" \ -o /pixi && chmod +x /pixiRUN /pixi --version
FROM --platform=linux/amd64 $BASE_IMAGE
# Add appuser with UID 1000RUN useradd -u 1000 -m -s /bin/bash appuserUSER appuserWORKDIR /home/appuser
# Copy pixi from builderCOPY --from=builder --chown=appuser:appuser --chmod=0555 /pixi /usr/local/bin/pixi
# Set up pixi with conda channelsENV PATH="/home/appuser/.pixi/bin:${PATH}"RUN pixi config set default-channels '["conda-forge", "bioconda"]' --global
# Install tools using pixiRUN pixi global install fastqc=0.12.1 samtools=1.18 bwa=0.7.17
# Clean cacheRUN pixi clean cache -y
WORKDIR /dataCMD ["/bin/bash"]Key Pixi features in the Dockerfile:
appuser for securitypixi global install installs and locks versionspixi clean cache -y removes temporary filesComparing container tools:
| Feature | Conda | Micromamba | Pixi |
|---|---|---|---|
| Speed | Baseline | Faster | Fast |
| Lock file | Manual export | Manual export | Automatic |
| Image size | Large | Small | Small |
| Reproducibility | Good | Strong | Strong |
| Complexity | High | Medium | Low |
| Learning curve | Steep | Medium | Low |
| Production-ready | Yes | Yes | Emerging |
Summary:
conda.yml with Micromamba for established, proven workflows.procps-ng for Nextflow compatibility, regardless of the tool used.Before spending time building Docker images from scratch, check whether the tool already exists in a public container registry. Many bioinformatics tools have pre-built, maintained containers ready to use.
A practical order is:
BioContainers builds and maintains Docker containers for bioconda packages. It is a common first stop for bioinformatics tools.
URL: https://biocontainers.pro/registry
How to find and use a tool:
# Search for FastQCdocker search quay.io/biocontainers/fastqc
# Pull a specific versiondocker pull quay.io/biocontainers/fastqc:0.12.1--hdfd78af_1
# Run the tooldocker run --rm -v "$PWD:/data" quay.io/biocontainers/fastqc:0.12.1--hdfd78af_1 \ fastqc /data/sample.fastq
Advantages:
Limitations:
Example with multiple tools in a workflow:
# Align reads with BWAdocker run --rm -v "$PWD:/data" quay.io/biocontainers/bwa:0.7.17--h5bf99c6_8 \ bwa mem /data/ref.fa /data/reads.fq > /data/aligned.sam
# Sort BAM with Samtoolsdocker run --rm -v "$PWD:/data" quay.io/biocontainers/samtools:1.18--hd87286a_0 \ samtools sort /data/aligned.sam > /data/aligned.bamSeqera Containers provides a registry of pre-built containers that often combine multiple tools, which suits complex workflows.
URL: https://seqera.io/containers/
How to find and use containers:
fastqc + samtools together)Example:
# Pull a multi-tool containerdocker pull wave.seqera.io/library/fastqc:0.12.1-samtools_1.18
# Or use in Nextflowprocess analyzeReads { container 'wave.seqera.io/library/fastqc:0.12.1-samtools_1.18' script: ''' fastqc input.fastq samtools view input.bam '''}
Advantages:
Limitations:
Building your own container is reasonable when:
Example scenario:
# Check if tool existsdocker pull quay.io/biocontainers/myraretool:latest # Not found
# Check Seqera Containers# Visit https://seqera.io/containers/ - (tool not found)
# → NOW you build it yourself using the Section 4 approachdocker build -t myregistry.com/myraretool:1.0 .docker push myregistry.com/myraretool:1.0| Tool type | Primary location | Alternative | Fallback |
|---|---|---|---|
| Common bioinformatics (FastQC, SAMtools, BWA, etc.) | https://biocontainers.pro/registry | https://seqera.io/containers/ | Build yourself |
| R/Bioconductor packages | https://biocontainers.pro/registry | https://seqera.io/containers/ | Build yourself |
| Python bioinformatics | https://biocontainers.pro/registry | https://seqera.io/containers/ | Build yourself |
| Specialized tools | https://biocontainers.pro/registry first | GitHub releases | Build yourself |
#!/bin/bash# 1. Search for tool in BioContainersTOOL="fastqc"VERSION="0.12.1"echo "Searching for $TOOL:$VERSION in BioContainers..."docker pull quay.io/biocontainers/$TOOL:$VERSION--* 2>/dev/null && \ echo "Found in BioContainers!" && \ exit 0
# 2. Try Seqera Containersecho "Trying Seqera Containers..."# (Check https://seqera.io/containers/ manually or via API)
# 3. Build yourselfecho "Not found in public registries. Building from scratch..."# Use the Section 4 approach with Micromamba or Pixidocker build -t myregistry.com/$TOOL:$VERSION .Pin exact versions:
✓ Good: docker pull quay.io/biocontainers/samtools:1.18--hd87286a_0✗ Bad: docker pull quay.io/biocontainers/samtools:latestUse the build digest in Nextflow:
process myTask { // Include digest for reproducibility container 'quay.io/biocontainers/samtools:1.18--hd87286a_0@sha256:abc123...' script: 'samtools view input.bam'}Keep a local cache for offline work:
docker pull quay.io/biocontainers/samtools:1.18--hd87286a_0docker tag quay.io/biocontainers/samtools:1.18--hd87286a_0 \ myregistry.com/samtools:1.18docker push myregistry.com/samtools:1.18Do you need a bioinformatics tool in a container?│├─→ Search https://biocontainers.pro/registry (BioContainers)│ ├─→ Found? Use it│ └─→ Not found?│ ││ ├─→ Search https://seqera.io/containers/ (Seqera Containers)│ │ ├─→ Found? Use it│ │ └─→ Not found?│ │ ││ │ └─→ Build using Section 4│ │ (Micromamba or Pixi)Key takeaway:



