npx claudepluginhub pjt222/agent-almanacThis skill uses the workspace's default tool permissions.
---
Build production-ready Dockerfiles with multi-stage builds, security hardening, and docker-compose for local dev. Use when asked to "create Dockerfile", "optimize container", or "dockerize this".
Generates optimized multi-stage Dockerfiles, .dockerignore, for Node.js, Python, Go, Java apps with security hardening, layer caching, validation, and error fixes.
Share bugs, ideas, or general feedback.
Build a Dockerfile for R projects using rocker base images with proper dependency management.
| Use Case | Base Image | Size |
|---|---|---|
| Minimal R runtime | rocker/r-ver:4.5.0 | ~800MB |
| With tidyverse | rocker/tidyverse:4.5.0 | ~1.8GB |
| With RStudio Server | rocker/rstudio:4.5.0 | ~1.9GB |
| Shiny server | rocker/shiny-verse:4.5.0 | ~2GB |
Expected: A base image is selected that matches the project's requirements without unnecessary bloat.
On failure: If unsure which image to use, start with rocker/r-ver (minimal) and add packages as needed. Check rocker-org for the full image catalog.
FROM rocker/r-ver:4.5.0
# Install system dependencies
# Group by purpose for clarity
RUN apt-get update && apt-get install -y \
# HTTP/SSL
libcurl4-openssl-dev \
libssl-dev \
# XML processing
libxml2-dev \
# Git integration
libgit2-dev \
libssh2-1-dev \
# Graphics
libfontconfig1-dev \
libharfbuzz-dev \
libfribidi-dev \
libfreetype6-dev \
libpng-dev \
libtiff5-dev \
libjpeg-dev \
# Utilities
git \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install R packages
# Order: least-changing first for cache efficiency
RUN R -e "install.packages(c( \
'remotes', \
'devtools', \
'renv' \
), repos='https://cloud.r-project.org/')"
# Set working directory
WORKDIR /workspace
# Copy renv files first (cache layer)
COPY renv.lock renv.lock
COPY renv/activate.R renv/activate.R
# Restore packages from lockfile
RUN R -e "renv::restore()"
# Copy project files
COPY . .
# Default command
CMD ["R"]
Expected: Dockerfile builds successfully with docker build -t myproject .
On failure: If the build fails during apt-get install, check package names for the target distro (Debian). If renv::restore() fails, ensure renv.lock and renv/activate.R are copied before the restore step.
.git
.Rproj.user
.Rhistory
.RData
renv/library
renv/cache
renv/staging
docs/
*.tar.gz
Expected: .dockerignore excludes Git history, IDE files, local renv library, and build artifacts from the Docker context.
On failure: If the Docker build still copies unwanted files, verify .dockerignore is in the same directory as the Dockerfile and uses correct glob patterns.
docker build -t r-project:latest .
docker run --rm -it r-project:latest R -e "sessionInfo()"
Expected: Container starts with correct R version and all packages available. sessionInfo() output confirms the expected R version.
On failure: Check build logs for system dependency errors. Add missing -dev packages to the apt-get install layer.
For production deployments, use multi-stage builds:
# Build stage
FROM rocker/r-ver:4.5.0 AS builder
RUN apt-get update && apt-get install -y libcurl4-openssl-dev libssl-dev
COPY renv.lock .
RUN R -e "install.packages('renv'); renv::restore()"
# Runtime stage
FROM rocker/r-ver:4.5.0
COPY --from=builder /usr/local/lib/R/site-library /usr/local/lib/R/site-library
COPY . /app
WORKDIR /app
CMD ["Rscript", "main.R"]
Expected: Multi-stage build produces a smaller final image. Runtime stage contains only compiled R packages, not build tools.
On failure: If packages fail to load in the runtime stage, ensure the library path in COPY --from=builder matches where R installed packages. Check with R -e ".libPaths()" in both stages.
docker build completes without errors.dockerignore excludes unnecessary files-dev libraries. Check error messages during install.packages()rm -rf /var/lib/apt/lists/* after apt-get install. Consider multi-stage builds.ENV TZ=UTC or install tzdata for timezone-aware operationsRUN useradd -m appuser && USER appuser# Development container with mounted source
docker run --rm -it -v $(pwd):/workspace r-project:latest R
# Plumber API service
docker run -d -p 8000:8000 r-api:latest
# Shiny app
docker run -d -p 3838:3838 r-shiny:latest
setup-docker-compose - orchestrate multiple containerscontainerize-mcp-server - special case for MCP R serversoptimize-docker-build-cache - advanced caching strategiesmanage-renv-dependencies - renv.lock feeds into Docker builds