| name | cwl-understand-docker |
| description | Understand Docker requirements in CWL packages including DockerRequirement configuration, image
selection, networking, and volume mounting. Learn best practices for containerized process
execution in Weaver. Use when creating Docker-based CWL packages or troubleshooting Docker-related
issues.
|
| license | Apache-2.0 |
| compatibility | Requires Docker understanding and CWL v1.0+. Docker must be available for local testing. |
| metadata | {"author":"fmigneault"} |
Understand Docker in CWL
Master Docker requirements and configuration in CWL packages for containerized process execution.
When to Use
- Creating Docker-based CWL packages
- Selecting appropriate Docker images
- Troubleshooting Docker-related failures
- Optimizing Docker image usage
- Understanding container execution in Weaver
- Configuring volume mounts and networking
DockerRequirement Basics
Simple Docker Requirement
cwlVersion: v1.2
class: CommandLineTool
baseCommand: [python, script.py]
requirements:
DockerRequirement:
dockerPull: python:3.12-slim
Docker with Specific Tag
requirements:
DockerRequirement:
dockerPull: ubuntu:20.04
Custom Docker Image
requirements:
DockerRequirement:
dockerPull: myregistry.io/myimage:v1.2.3
Docker Image Selection
Official Images (Recommended)
DockerRequirement:
dockerPull: python:3.12-slim
dockerPull: node:16-alpine
dockerPull: openjdk:11-jre-slim
dockerPull: debian:bullseye-slim
dockerPull: ubuntu:22.04
Scientific Images
DockerRequirement:
dockerPull: continuumio/miniconda3:latest
dockerPull: jupyter/scipy-notebook:latest
dockerPull: rocker/r-ver:4.2.0
Geospatial Images
DockerRequirement:
dockerPull: osgeo/gdal:ubuntu-small-latest
dockerPull: ghcr.io/osgeo/proj:9.1.0
Docker Image Best Practices
Use Specific Tags
dockerPull: python:latest
dockerPull: python:3.12.16-slim
Prefer Slim/Alpine Variants
dockerPull: python:3.12
dockerPull: python:3.12-slim
dockerPull: python:3.12-alpine
Pin Versions for Reproducibility
dockerPull: myorg/myimage:1.2.3
dockerPull: myorg/myimage@sha256:abc123...
Advanced Docker Configuration
Environment Variables
requirements:
DockerRequirement:
dockerPull: myimage:latest
EnvVarRequirement:
envDef:
PYTHONUNBUFFERED: "1"
TZ: "UTC"
DATA_PATH: "/data"
Network Access
requirements:
DockerRequirement:
dockerPull: myimage:latest
NetworkAccess:
networkAccess: true
Resource Limits
requirements:
DockerRequirement:
dockerPull: myimage:latest
ResourceRequirement:
coresMin: 2
coresMax: 4
ramMin: 4096
ramMax: 8192
tmpdirMin: 1024
outdirMin: 2048
Working with Files in Docker
Input Files
inputs:
input_file:
type: File
inputBinding:
position: 1
Output Files
outputs:
output_file:
type: File
outputBinding:
glob: "output.txt"
Directory Inputs
inputs:
input_dir:
type: Directory
inputBinding:
position: 1
Common Docker Patterns
Python Script Execution
cwlVersion: v1.2
class: CommandLineTool
baseCommand: [python]
requirements:
DockerRequirement:
dockerPull: python:3.12-slim
InitialWorkDirRequirement:
listing:
- entryname: script.py
entry: |
import sys
print(f"Processing {sys.argv[1]}")
arguments:
- script.py
- $(inputs.input_file.path)
inputs:
input_file: File
outputs:
stdout_log:
type: stdout
Installing Dependencies
requirements:
DockerRequirement:
dockerPull: python:3.12-slim
InitialWorkDirRequirement:
listing:
- entryname: requirements.txt
entry: |
numpy==1.24.0
pandas==1.5.3
- entryname: install-deps.sh
entry: |
#!/bin/bash
pip install -r requirements.txt
baseCommand: [bash, install-deps.sh, "&&", python, script.py]
Running Shell Scripts
requirements:
DockerRequirement:
dockerPull: bash:5.1
InitialWorkDirRequirement:
listing:
- entryname: script.sh
entry: |
#!/bin/bash
set -e
echo "Processing..."
# Your script here
baseCommand: [bash, script.sh]
Docker Troubleshooting
Image Pull Failures
Problem: Cannot pull image
Error: Failed to pull image 'myimage:latest'
Solutions:
docker pull myimage:latest
dockerPull: docker.io/library/myimage:latest
Permission Issues
Problem: Cannot write files
Error: Permission denied writing to /output
Solution:
requirements:
DockerRequirement:
dockerPull: myimage:latest
Missing Dependencies
Problem: Command not found in container
Error: bash: mycommand: command not found
Solutions:
dockerPull: image-with-mycommand:latest
InitialWorkDirRequirement:
listing:
- entryname: install.sh
entry: |
apt-get update && apt-get install -y mycommand
Network Access Issues
Problem: Cannot download files
Error: Unable to connect to remote server
Solution:
requirements:
NetworkAccess:
networkAccess: true
Docker Security Considerations
Use Trusted Images
dockerPull: python:3.12-slim
dockerPull: bitnami/python:3.12
dockerPull: randomuser/unknownimage:latest
Minimize Image Size
FROM python:3.12 AS builder
FROM python:3.12-slim
Keep Images Updated
dockerPull: python:3.12.17-slim
Integration with Weaver
Deploy Docker-based Process
cat > process.cwl << 'EOF'
cwlVersion: v1.2
class: CommandLineTool
baseCommand: [python, -c]
requirements:
DockerRequirement:
dockerPull: python:3.12-slim
arguments:
- "print('Hello from Docker')"
outputs:
stdout: stdout
EOF
cwltool --validate process.cwl
weaver deploy -u $WEAVER_URL -p docker-hello -b process.cwl
Monitor Docker Execution
JOB_ID=$(weaver execute -u $WEAVER_URL -p docker-hello -f json | jq -r .jobID)
weaver logs -u $WEAVER_URL -j $JOB_ID
Related Skills
Documentation
Tools
- docker pull: Test image availability
- docker run: Test container locally
- dive: Analyze image layers
- trivy: Scan for vulnerabilities
Best Practices Summary
- ✅ Use specific image tags (not
latest)
- ✅ Prefer official and verified images
- ✅ Use slim/alpine variants when possible
- ✅ Pin versions for reproducibility
- ✅ Test locally before deploying
- ✅ Enable NetworkAccess if needed
- ✅ Handle file permissions appropriately
- ✅ Keep images updated and secure
- ✅ Document why specific images are chosen
- ✅ Consider image size and pull time