Docker — Professional Tutorial for Life Sciences

Industry-standard Docker guide for bioinformatics, clinical programming, pharma, and data science.
Note

Audience: Students, bioinformatics researchers, clinical programmers, data scientists, pharmaceutical professionals, and software engineers — including readers with little or no prior experience.

1. Introduction

Docker is a platform that packages an application and everything it needs to run — code, libraries, settings — into a portable unit called a container.

Why Docker exists

Before containers, teams struggled with a familiar problem: “It works on my machine.” Different laptops, servers, and cloud environments had different software versions. Results changed. Audits failed. Pipelines broke in production.

Docker was created to make software portable, repeatable, and isolated.

The problem Docker solves

Problem Without Docker With Docker
Environment differences Results vary by machine Same image → same behavior
Complex installs Days installing bioinformatics tools Pull a pre-built image in minutes
Reproducibility Hard to prove what ran Versioned images document the environment
Isolation Tools conflict on one server Each container runs independently

Where Docker is used in industry

  • Pharmaceutical R&D — reproducible ML and cheminformatics environments
  • Clinical programming — fixed R/SAS/Python stacks for TLF generation
  • Bioinformatics — pipelines for genomics, proteomics, and multi-omics
  • Healthcare AI — deploying models in controlled containers
  • Cloud & DevOps — AWS ECS, Google Cloud Run, Kubernetes workloads
Tip

Beginner takeaway: Docker is a standardized box for software. Same box, same result — on your laptop, a lab server, or the cloud.


2. Learning Objectives

By the end of this tutorial, you will be able to

  1. Explain what Docker is and why regulated industries use it
  2. Install Docker Desktop on Windows, macOS, or Linux
  3. Distinguish images, containers, registries, volumes, and networks
  4. Build a custom image using a Dockerfile
  5. Run, stop, and remove containers from the command line
  6. Mount data safely without baking sensitive files into images
  7. Describe where Docker fits in bioinformatics and clinical programming workflows
  8. Apply industry best practices for security, GxP, and reproducibility
  9. Troubleshoot common Docker errors
  10. Complete a mini project: a reproducible clinical summary container

3. Why is this important?

Why should someone learn Docker?

Docker is one of the most requested skills in bioinformatics, data engineering, and DevOps job postings. It turns fragile setups into shareable, testable environments.

Why do companies use it?

  • Speed — onboard new analysts in hours, not weeks
  • Compliance — versioned images support audit trails
  • Scale — same container runs on one laptop or 1,000 cloud nodes
  • Cost — efficient resource use compared to full virtual machines

Why is it important in bioinformatics?

Genomics pipelines combine dozens of tools (FastQC, BWA, GATK, bcftools). Docker (and Biocontainers) pins exact versions so published results can be reproduced.

Why is it important in clinical programming?

Clinical trial analysis must be reproducible. Docker ensures the same R packages, SAS components, or Python libraries are used for every database lock and QC re-run.

Why is it useful in data science?

Data scientists package models with dependencies so staging and production environments match — reducing “model works locally but fails in deployment” issues.


4. Architecture Diagram

Docker core architecture

Life-sciences workflow placement

Important

Screenshot placeholder: Add a screenshot of Docker Desktop showing a running container after completing Section 5.


5. Installation

Windows

  1. Download Docker Desktop for Windows
  2. Enable WSL 2 if prompted (recommended)
  3. Install and restart
  4. Open Docker Desktop and wait until status shows Running

Verify:

docker --version
docker run hello-world

macOS

  1. Download Docker Desktop for Mac (Apple Silicon or Intel)
  2. Drag Docker to Applications and launch
  3. Accept permissions

Verify:

docker --version
docker run hello-world

Linux (Ubuntu/Debian example)

# Install Docker Engine
sudo apt-get update
sudo apt-get install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Optional: run without sudo
sudo usermod -aG docker $USER
newgrp docker

Verify:

docker --version
docker run hello-world
Warning

Corporate laptops may block Docker. Contact IT before installing in pharmaceutical or hospital environments.


6. Basic Concepts

Image

Definition Read-only template containing an app and its dependencies
Analogy A sealed recipe kit with pre-measured ingredients
Industry example rocker/r-ver:4.3.2 for a locked clinical R environment
Best practice Always use specific version tags — never :latest in production

Container

Definition A running instance of an image
Analogy The actual meal cooked from the recipe kit
Industry example One container per study analysis run
Best practice Use --rm for temporary jobs; name containers in long-running services

Registry

Definition Storage and distribution system for images
Analogy A warehouse catalog of standardized boxes
Industry example Private AWS ECR registry for validated pharma images
Best practice Use private registries for internal and GxP workloads

Docker Hub

Definition Public registry maintained by Docker
Analogy An app store for container images
Industry example Pulling official python:3.11-slim base images
Best practice Prefer verified publishers; scan images for vulnerabilities

Dockerfile

Definition Text file with step-by-step instructions to build an image
Analogy The master recipe card
Industry example Documented build file archived with study deliverables
Best practice Keep Dockerfiles in version control; review changes like code

Volume

Definition Persistent storage mounted into a container
Analogy A USB drive plugged into the box
Industry example Mount clinical CSV input and TLF output folders
Best practice Never store patient data inside the image — mount at runtime

Network

Definition Virtual network allowing containers to communicate
Analogy Phone lines between offices in the same building
Industry example Connect a Shiny app container to a PostgreSQL container
Best practice Use custom networks; avoid exposing unnecessary ports

7. Hands-on Examples

Example 1 — Hello World

Problem: Confirm Docker is installed and working.

Solution: Run the official test image.

docker run hello-world

Expected output: Message containing Hello from Docker!

Explanation: Docker downloaded a tiny image, started a container, printed output, and exited.


Example 2 — Run R without installing R

Problem: You need R 4.3 but do not want to install it locally.

Solution:

docker run --rm rocker/r-ver:4.3 R --version

Expected output: R version 4.3.x ...

Explanation: The container includes R; your host machine stays unchanged.


Example 3 — Interactive Python shell

Problem: Test Python in an isolated environment.

Solution:

docker run -it --rm python:3.11-slim python
print("Docker Python ready")
exit()

Expected result: Python REPL opens, prints message, exits cleanly.


Example 4 — Build a clinical summary image

Problem: Create a reproducible environment for summarizing patient ages.

Solution:

Create summarize.R:

args <- commandArgs(trailingOnly = TRUE)
dat <- read.csv(args[1])
out <- data.frame(
  n = nrow(dat),
  mean_age = round(mean(dat$age, na.rm = TRUE), 1)
)
write.csv(out, args[2], row.names = FALSE)
cat("Done\n")

Create patients.csv:

patient_id,age
001,54
002,61
003,47

Create Dockerfile:

FROM rocker/r-ver:4.3
WORKDIR /analysis
COPY summarize.R patients.csv ./
CMD ["Rscript", "summarize.R", "patients.csv", "summary.csv"]

Build and run:

docker build -t clinical-summary:1.0 .
docker run --rm -v "$(pwd):/output" clinical-summary:1.0 \
  sh -c "Rscript summarize.R patients.csv /output/summary.csv"
cat summary.csv

Expected output: CSV with n and mean_age.

Explanation: Image tag clinical-summary:1.0 documents the exact environment used.


Example 5 — Pull a bioinformatics tool

Problem: Run FastQC without manual installation.

Solution:

docker run --rm biocontainers/fastqc:v0.11.9_cv8 fastqc --help

Expected result: FastQC help text displayed.


8. Real-world Industry Use Cases

# Industry Use case How Docker helps
1 Bioinformatics WGS variant calling Pins BWA, GATK, bcftools versions
2 Pharma Drug target ML models Same model container in dev and prod
3 Clinical trials TLF regeneration Locked R/SAS environment per study
4 Healthcare Diagnostic AI deployment Isolated, scalable inference containers
5 CRO Multi-study platforms Separate containers per sponsor data
6 Manufacturing Batch QC analytics Validated image versions per SOP
7 Real-world evidence Claims data pipelines Reproducible ETL in the cloud
8 Genomics core lab High-throughput FASTQ QC Parallel containers per sample
9 Regulatory Audit reproduction Image digest proves what executed
10 Data engineering ETL to data lake Portable Spark/Python worker images
11 AI/ML Model serving FastAPI/Torch images on Kubernetes
12 Clinical programming ADaM validation Shared env for independent QC stats

9. Bioinformatics Workflow

Role of Docker: Each pipeline step (FastQC, alignment, calling) runs inside a container with an exact tool version. Nextflow orchestrates which container runs when. This prevents tool-version drift across samples and sites.


10. Clinical Programming Workflow

How Docker helps:

  • SDTM/ADaM conversion — same R/Python/Pinnacle21 automation environment every lock
  • Analysis — reproducible rocker/tidyverse or SAS-compatible stacks
  • TLFs — QC statisticians re-run the identical container to verify outputs
  • Submission — image tags archived alongside analysis documentation
Warning

Docker supports reproducibility but does not replace formal CSV, SOPs, or 21 CFR Part 11 controls by itself.


11. Best Practices

DO

  • Pin image versions (:1.0, :2024-06-28)
  • Store Dockerfiles in Git
  • Use multi-stage builds to reduce image size
  • Scan images for CVEs (Trivy, Snyk)
  • Mount data with volumes; keep PHI out of images
  • Document image digest in study files

DON’T

  • Use :latest in regulated production
  • Run containers as root when avoidable
  • Store passwords or API keys in Dockerfiles
  • Copy patient datasets into image layers
  • Expose unnecessary ports to the internet

Performance tips

  • Use -slim or -alpine base images
  • Leverage build cache; order Dockerfile layers from least to most frequently changed
  • Prune unused images: docker system prune

Security tips

  • Use private registries for internal images
  • Enable Docker Content Trust where required
  • Apply least-privilege IAM on cloud registries

Optimization tips

  • One process per container when possible
  • Use .dockerignore to speed builds
  • Compose multi-container apps with Docker Compose for local dev

12. Common Mistakes

Mistake Reason Solution
Docker Desktop not running Service stopped after reboot Launch Docker Desktop; wait for green status
permission denied on Linux User not in docker group sudo usermod -aG docker $USER
Huge images Installing unnecessary packages Use slim bases; multi-stage builds
Data lost after container stops Wrote inside container filesystem Use volumes for persistent output
Wrong architecture image Apple Silicon vs x86 mismatch Select arm64 or use --platform linux/amd64
PHI in image layers Copied data in Dockerfile Mount volumes at runtime only
Port already in use Another service on same port Change host port: -p 8081:8080
Cannot pull image Network/proxy/firewall Configure proxy; use internal mirror

13. Troubleshooting Guide

Error Cause Solution
Cannot connect to the Docker daemon Docker not running Start Docker Desktop / sudo systemctl start docker
pull access denied Private image or auth needed docker login to registry
no space left on device Disk full docker system df then docker system prune -a
exec format error CPU architecture mismatch Use correct platform image
port is already allocated Port conflict Stop other service or change mapping
Build fails at COPY File missing from context Check path and .dockerignore
Container exits immediately CMD error Run interactively: docker run -it image sh
Slow performance on Mac File sharing overhead Use delegated mounts; limit watched folders

Useful diagnostic commands:

docker ps -a
docker logs CONTAINER_ID
docker inspect IMAGE_NAME
docker system df
docker info

14. Interview Questions

Beginner

Q1: What is the difference between an image and a container?
A: An image is a read-only template; a container is a running instance of that image.

Q2: What is Docker Hub?
A: A public registry for storing and sharing container images.

Q3: Why do bioinformatics teams use Docker?
A: To pin tool versions and reproduce pipeline results across machines.

Intermediate

Q4: What is a volume and when would you use one?
A: Persistent storage mounted into a container — used for input data and output results without baking them into the image.

Q5: How do Docker and Kubernetes relate?
A: Docker builds/runs containers locally; Kubernetes orchestrates many containers across a cluster.

Q6: How would you make a clinical analysis reproducible with Docker?
A: Build a versioned image, document the tag/digest, mount study data at runtime, archive the Dockerfile in version control.

Advanced

Q7: What are multi-stage builds?
A: Dockerfiles with multiple FROM stages — compile in one stage, copy only artifacts to a smaller final image.

Q8: How do you reduce attack surface in production containers?
A: Non-root user, minimal base image, no secrets in layers, regular scanning, read-only filesystem where possible.

Q9: Explain how Nextflow uses Docker.
A: Each process specifies a container image; Nextflow pulls and runs it per task, enabling reproducible scalable pipelines.


15. Cheat Sheet

# Info
docker --version
docker info

# Images
docker pull IMAGE:TAG
docker images
docker build -t NAME:TAG .
docker rmi IMAGE

# Containers
docker run --rm IMAGE
docker run -it --rm IMAGE sh
docker ps
docker ps -a
docker stop ID
docker logs ID
docker exec -it ID sh

# Data
docker run -v "$(pwd):/data" IMAGE

# Cleanup
docker system prune
docker system prune -a
Tip Command
Remove container after exit --rm
Interactive terminal -it
Name a container --name myjob
Map port -p 8080:80
Env variable -e VAR=value

16. Summary

  • Docker packages apps and dependencies into portable containers
  • An image is the template; a container is the running instance
  • Docker solves reproducibility, isolation, and deployment consistency
  • Life-sciences teams use Docker for genomics pipelines, clinical analysis, and ML
  • Install via Docker Desktop (Windows/Mac) or Docker Engine (Linux)
  • Build custom environments with a Dockerfile
  • Use volumes for data — never embed PHI in images
  • Pin version tags for regulated and scientific work
  • Combine Docker with Nextflow for scalable bioinformatics
  • Combine Docker with Quarto for reproducible reports
  • Scan images, prune disk usage, and document image digests
  • Troubleshoot with docker logs, docker ps, and docker inspect
  • Next recommended topics: Linux → Git → Nextflow → Kubernetes → AWS

17. Next Topic

After Docker, learn Nextflow to orchestrate multi-step pipelines, or Linux foundations if you are new to the command line.


18. Learning Path

Bioinformatics roadmap

Clinical programming roadmap


19. Further Reading

Resource Link
Official Docker docs https://docs.docker.com/
Docker GitHub https://github.com/docker
Biocontainers https://biocontainers.pro/
Rocker (R images) https://rocker-project.org/
Google Cloud Run + containers https://cloud.google.com/run/docs
NF-Core (Nextflow + Docker) https://nf-co.re/
Book Docker Deep Dive — Nigel Poulton
YouTube Docker official channel, TechWorld with Nana

20. Mini Project — Reproducible Study Summary Container

Problem statement

Build a Dockerized R environment that reads a patient CSV and writes a summary CSV — suitable for QC documentation in a mock clinical study.

Architecture

Folder structure

clinical-docker-project/
├── Dockerfile
├── summarize.R
├── patients.csv
└── README.md

Commands

mkdir clinical-docker-project && cd clinical-docker-project
# Add Dockerfile, summarize.R, patients.csv from Example 4
docker build -t study-qc:1.0 .
docker run --rm -v "$(pwd):/output" study-qc:1.0 \
  sh -c "Rscript summarize.R patients.csv /output/summary.csv"

Expected output

summary.csv containing record count and mean age — reproducible when the same study-qc:1.0 image is used.

Tip

Archive the image tag and Git commit hash in your mock study documentation to practice GxP-style traceability.


21. Exercises

10 practice questions

  1. Define image vs container in your own words.
  2. What command verifies Docker installation?
  3. Why should you avoid :latest in production?
  4. What flag removes a container after it exits?
  5. How do you mount the current directory into a container?
  6. Name two life-sciences registries or image sources.
  7. Where does Docker fit in a FASTQ-to-VCF pipeline?
  8. Why should PHI not be copied into a Dockerfile?
  9. What command lists running containers?
  10. How does Docker help clinical TLF QC?

5 assignments

  1. Build an image with Python 3.11 that prints today’s date.
  2. Run rocker/tidyverse and execute a dplyr pipeline inside the container.
  3. Create a .dockerignore and explain what it excludes.
  4. Pull a Biocontainers image and document its tag.
  5. Write a one-page SOP for naming and tagging study images.

3 mini projects

  1. Dockerize a simple FastQC command on a sample FASTQ file.
  2. Build a two-stage Dockerfile (build tools → minimal runtime).
  3. Compose a web app + database with Docker Compose locally.

1 capstone project

Design a reproducible mini pipeline: QC → summary stats → Quarto HTML report — each step in its own versioned container, orchestrated manually or with Nextflow.


Back to home