

Running interactive web applications such as RStudio, JupyterLab, and Code Server in containers is a common way to provide reproducible analysis environments. These applications often need to spawn additional containerized tools from within. Docker out of Docker (DooD) addresses this by letting a container access the host's Docker daemon. This post describes how to set up DooD for interactive web applications and the trade-offs involved.
RStudio Server with containerized tools
User opens RStudio in browser ↓Inside RStudio, run: system("docker run quay.io/biocontainers/samtools:latest samtools ...") ↓Needs access to host Docker daemonJupyterLab with Cell Ranger analysis
User runs notebook cell with: !docker run cellranger:v7.0 cellranger count ... ↓Needs Docker access from within JupyterLab container ↓Results written back to shared volumeCode Server for pipeline development
User edits Nextflow script in Code Server ↓Runs: docker exec to test containerized tools locally ↓Needs full Docker CLI accessWeb applications like RStudio, JupyterLab, and Code Server generally need to:
DooD provides these through a socket mount.
DooD mounts the host's Docker socket (/var/run/docker.sock) into the container. This lets processes inside the container communicate directly with the host's Docker daemon.
Key point: containers spawned from within the DooD container appear as siblings to the web application container, not children. They run directly on the host, with access to host resources and volumes.
Architecture:
Host System├── Docker Daemon (listening on /var/run/docker.sock)├── Host volumes (/data, /workspace)│└── Web App Container (RStudio/JupyterLab/Code Server) ├── Mounts: /var/run/docker.sock:/var/run/docker.sock ├── Mounts: /data:/data, /workspace:/workspace │ ├── User runs: docker run quay.io/biocontainers/bwa:latest ... │ └── → Uses HOST Docker daemon to spawn sibling container → Spawned container has full access to host volumes → Results written back to shared volume → Web app container can access resultsLimited resource overhead
Simple volume sharing
Full Docker access
docker ps, docker pull, docker build all workBasic RStudio with DooD:
#!/bin/bashdocker run \ --rm \ -p 8787:8787 \ -e PASSWORD=mypassword \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /home/user/data:/data \ -v /home/user/workspace:/workspace \ rocker/tidyverse:latestExplanation:
-p 8787:8787: RStudio web interface on port 8787-e PASSWORD=mypassword: set the RStudio password-v /var/run/docker.sock:/var/run/docker.sock: mount the Docker socket (enables DooD)-v /home/user/data:/data: share the data directory-v /home/user/workspace:/workspace: share the workspace directoryOnce RStudio is running, Docker can be used directly from the R console or shell.
Running samtools from RStudio:
# In RStudio consolesystem('docker run --rm -v /data:/data quay.io/biocontainers/samtools:latest samtools view -h /data/input.bam | head')Running a bwa alignment:
# Run bwa in Docker containercmd <- 'docker run --rm -v /data:/data -v /workspace:/workspace quay.io/biocontainers/bwa:latest bwa mem /data/ref.fa /data/reads.fastq > /workspace/aligned.sam'system(cmd)
# Read results back into Ralignment <- read.table('/workspace/aligned.sam', skip=10)head(alignment)Running Cell Ranger from RStudio:
# In RStudio terminal or system()system('docker run --rm \\ -v /var/run/docker.sock:/var/run/docker.sock \\ -v /data:/data \\ cellranger:v7.0 \\ cellranger count \\ --id=sample1 \\ --fastqs=/data/fastqs \\ --transcriptome=/data/reference')
# Load resultslibrary(Seurat)data <- Read10X_h5('/data/sample1/outs/filtered_feature_bc_matrix.h5')A more production-ready setup with docker-compose:
version: '3.8'
services: rstudio: image: rocker/tidyverse:4.3.0 container_name: rstudio-analysis ports: - "8787:8787" environment: - PASSWORD=secure_password - USER=researcher volumes: # Mount Docker socket for DooD - /var/run/docker.sock:/var/run/docker.sock # Mount data directories - ./data:/data:rw - ./workspace:/workspace:rw - ./projects:/home/rstudio/projects:rw restart: unless-stopped # Optional: limit resources deploy: resources: limits: cpus: '4' memory: 16GRun with:
docker-compose up -d# Access at http://localhost:8787# Username: researcher# Password: secure_passwordBasic JupyterLab with DooD:
#!/bin/bashdocker run \ --rm \ -p 8888:8888 \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /home/user/data:/data \ -v /home/user/notebooks:/notebooks \ jupyter/scipy-notebook:latest \ jupyter lab --ip=0.0.0.0 --allow-root --no-browserGet the token from the logs:
# Output will show: http://127.0.0.1:8888/lab?token=xxxxx# Use that to access JupyterLab in browserRunning bioinformatics tools in notebook cells:
# In JupyterLab cell - run samtools in Dockerimport subprocess
result = subprocess.run([ 'docker', 'run', '--rm', '-v', '/data:/data', 'quay.io/biocontainers/samtools:latest', 'samtools', 'view', '-h', '/data/input.bam'], capture_output=True, text=True)
print(result.stdout)Processing with Docker and Python integration:
# Cell 1: Run analysis in containerimport subprocessimport json
# Run Cell Ranger in Dockersubprocess.run([ 'docker', 'run', '--rm', '-v', '/data:/data', 'cellranger:v7.0', 'cellranger', 'count', '--id=sample1', '--fastqs=/data/fastqs', '--transcriptome=/data/reference'])
# Cell 2: Load results in Pythonimport scanpy as sc
adata = sc.read_h5ad('/data/sample1/outs/filtered_feature_bc_matrix.h5')print(adata)Running FastQC on multiple samples:
import subprocessimport osfrom pathlib import Path
fastq_dir = '/data/fastqs'
# Run FastQC on all FASTQ filesfor fastq_file in Path(fastq_dir).glob('*.fastq.gz'): subprocess.run([ 'docker', 'run', '--rm', '-v', '/data:/data', 'quay.io/biocontainers/fastqc:latest', 'fastqc', f'/data/fastqs/{fastq_file.name}', '-o', '/data/qc_results' ])
print("FastQC analysis complete")version: '3.8'
services: jupyter: image: jupyter/scipy-notebook:latest container_name: jupyterlab-analysis ports: - "8888:8888" volumes: # Mount Docker socket for DooD - /var/run/docker.sock:/var/run/docker.sock # Mount analysis directories - ./data:/data:rw - ./notebooks:/notebooks:rw - ./output:/output:rw environment: - JUPYTER_ENABLE_LAB=yes command: > jupyter lab --ip=0.0.0.0 --port=8888 --allow-root --no-browser restart: unless-stoppedCode Server with full Docker access:
#!/bin/bashdocker run \ --rm \ -p 8443:8443 \ -e PASSWORD=mypassword \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /home/user/workspace:/home/coder/project \ -v /home/user/data:/data \ codercom/code-server:latestAccess at: https://localhost:8443
Integrated terminal for Docker commands:
# In Code Server terminaldocker psdocker pull quay.io/biocontainers/nextflow:latestdocker run --rm quay.io/biocontainers/nextflow:latest nextflow --versionRunning and debugging Nextflow workflows:
# In Code Server terminal - edit Nextflow scriptcat > /workspace/main.nf << 'EOF'process alignment { container 'quay.io/biocontainers/bwa:latest' input: path reference path reads
output: path "*.sam"
script: """ bwa mem $reference $reads > aligned.sam """}EOF
# Run workflow locally with Dockernextflow run main.nf -with-dockerversion: '3.8'
services: code-server: image: codercom/code-server:latest container_name: code-server-dev ports: - "8443:8443" environment: - PASSWORD=secure_password - SUDO_PASSWORD=secure_password volumes: # Mount Docker socket for DooD - /var/run/docker.sock:/var/run/docker.sock # Mount workspace - ./workspace:/home/coder/project:rw - ./data:/data:rw restart: unless-stoppedRun RStudio, JupyterLab, and Code Server together:
version: '3.8'
services: rstudio: image: rocker/tidyverse:4.3.0 container_name: rstudio ports: - "8787:8787" environment: - PASSWORD=rstudio_password volumes: - /var/run/docker.sock:/var/run/docker.sock - ./data:/data:rw - ./workspace:/workspace:rw restart: unless-stopped
jupyter: image: jupyter/scipy-notebook:latest container_name: jupyter ports: - "8888:8888" volumes: - /var/run/docker.sock:/var/run/docker.sock - ./data:/data:rw - ./notebooks:/notebooks:rw command: > jupyter lab --ip=0.0.0.0 --allow-root --no-browser restart: unless-stopped
code-server: image: codercom/code-server:latest container_name: code-server ports: - "8443:8443" environment: - PASSWORD=code_password volumes: - /var/run/docker.sock:/var/run/docker.sock - ./workspace:/home/coder/project:rw - ./data:/data:rw restart: unless-stopped
# Optional: shared data volume container data: image: alpine:latest volumes: - ./data:/data:rw command: /bin/sh -c "echo 'Data container for shared volumes'"Run all services:
docker-compose up -d
# Access:# RStudio: http://localhost:8787# JupyterLab: http://localhost:8888# Code Server: https://localhost:8443File permissions:
#!/bin/bash# Files created in Docker containers may have root ownership# Run containers with explicit user mapping
docker run \ -u $(id -u):$(id -g) \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /data:/data \ ubuntu:22.04 \ touch /data/file.txtDocker daemon access:
Warning: mounting /var/run/docker.sock grants full Docker daemon access. Use it only in:
Do not expose this to untrusted users or the public internet.
Limit container resources:
docker run \ --cpus 4 \ --memory 16g \ -v /var/run/docker.sock:/var/run/docker.sock \ rocker/tidyverse:latestIn docker-compose:
services: rstudio: image: rocker/tidyverse:latest deploy: resources: limits: cpus: '4' memory: 16G reservations: cpus: '2' memory: 8GPractices for shared volumes:
#!/bin/bash# Create named volume for data persistencedocker volume create analysis-data
# Mount in multiple containersdocker run -v analysis-data:/data rstudiodocker run -v analysis-data:/data jupyterdocker run -v analysis-data:/data code-serverProblem: Cannot connect to Docker daemon
Solution:
# Check Docker socket permissionsls -la /var/run/docker.sock
# Add current user to docker groupsudo usermod -aG docker $USERnewgrp docker
# Or run container with docker groupdocker run \ --group-add $(getent group docker | cut -d: -f3) \ -v /var/run/docker.sock:/var/run/docker.sock \ rocker/tidyverse:latestProblem: cannot modify files created by Docker containers
Solution:
# Run containers with user/group mappingdocker run \ -u $(id -u):$(id -g) \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /data:/data \ rocker/tidyverse:latestProblem: files in mounted volumes are not visible from the web app
Solution:
# Verify volume is mounteddocker inspect rstudio-container | grep Mounts
# Use absolute pathsdocker run \ -v /home/user/data:/data \ -v /var/run/docker.sock:/var/run/docker.sock \ rocker/tidyverse:latestDocker out of Docker is a practical approach for running interactive web applications that need to spawn containerized bioinformatics tools. It provides:
Key points:
/var/run/docker.sock to enable DooD




