本文へ移動
cccskills
無料GitHub で公開

create-r-dockerfile

Create a Dockerfile for R projects using rocker base images. Covers system dependency installation, R package installation, renv integration, and optimized layer ordering for fast rebuilds. Use when containerizing an R application or analysis, creating reproducible R environments, deploying R-based services (Shiny, Plumber, MCP server), or setting up consistent development environments across machines.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md6.1 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Create R Dockerfile

Build a Dockerfile for R projects using rocker base images with proper dependency management.

When to Use

  • Containerizing an R application or analysis
  • Creating reproducible R environments
  • Deploying R-based services (Shiny, Plumber, MCP server)
  • Setting up consistent development environments

Inputs

  • Required: R project with dependencies (DESCRIPTION or renv.lock)
  • Required: Purpose (development, production, or service)
  • Optional: R version (default: latest stable)
  • Optional: Additional system libraries needed

Procedure

Step 1: Choose Base Image

Use CaseBase ImageSize
Minimal R runtimerocker/r-ver:4.5.0~800MB
With tidyverserocker/tidyverse:4.5.0~1.8GB
With RStudio Serverrocker/rstudio:4.5.0~1.9GB
Shiny serverrocker/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.

Step 2: Write Dockerfile

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.

Step 3: Create .dockerignore

.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.

Step 4: Build and Test

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.

Step 5: Optimize for Production

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.

Validation

  • docker build completes without errors
  • Container starts and R session works
  • All required packages are available
  • .dockerignore excludes unnecessary files
  • Image size is reasonable for the use case
  • Rebuilds are fast when only code changes (layer caching works)

Common Pitfalls

  • Missing system dependencies: R packages with compiled code need -dev libraries. Check error messages during install.packages()
  • Layer cache invalidation: Copying all files before installing packages invalidates cache on every code change. Copy lockfile first.
  • Large images: Use rm -rf /var/lib/apt/lists/* after apt-get install. Consider multi-stage builds.
  • Timezone issues: Add ENV TZ=UTC or install tzdata for timezone-aware operations
  • Running as root: Add a non-root user for production: RUN useradd -m appuser && USER appuser

Examples

# 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

Related Skills

  • setup-docker-compose - orchestrate multiple containers
  • containerize-mcp-server - special case for MCP R servers
  • optimize-docker-build-cache - advanced caching strategies
  • manage-renv-dependencies - renv.lock feeds into Docker builds

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Execute structural metamorphosis using strangler fig migration, chrysalis phases, and interface preservation. Covers transformation planning, parallel running, progressive cutover, rollback design, and post-metamorphosis stabilization for system architecture evolution. Use when assess-form has classified the system as READY for transformation, when migrating from monolith to microservices, when replacing a core subsystem while dependents continue operating, or when any architectural change must be gradual rather than big-bang.

日本語の概要は準備中です。原文の説明を表示しています。

pjt222/agent-almanac372026年10月10日 更新

adaptic

無料

Master skill composing the 5-step synoptic cycle for panoramic synthesis across multiple domains. Orchestrates meditate, expand-awareness, observe, awareness, integrate-gestalt, and express-insight into a coherent process that produces unified understanding rather than sequential compromise. Use when a problem genuinely spans 3+ domains and the interactions between domains matter more than depth in any one, when sequential analysis feels like compromise rather than integration, or before major architectural decisions affecting multiple stakeholders.

日本語の概要は準備中です。原文の説明を表示しています。

pjt222/agent-almanac372026年10月10日 更新

Scaffold a new puzzle type across all 10+ pipeline integration points in jigsawR. Creates the core puzzle module, wires it into the unified pipeline (generation, positioning, rendering, adjacency), adds ggpuzzle geom/stat layers, updates DESCRIPTION and config.yml, extends the Shiny app, and creates a comprehensive test suite. Use when adding a completely new puzzle type to the package or following the 10-point integration checklist to ensure nothing is missed end-to-end.

日本語の概要は準備中です。原文の説明を表示しています。

pjt222/agent-almanac372026年10月10日 更新

Add Rcpp or RcppArmadillo integration to an R package for high-performance C++ code. Covers setup, writing C++ functions, RcppExports generation, testing compiled code, and debugging. Use when an R function is too slow and profiling confirms a bottleneck, when you need to interface with existing C/C++ libraries, or when implementing algorithms (loops, recursion, linear algebra) that benefit from compiled code.

日本語の概要は準備中です。原文の説明を表示しています。

pjt222/agent-almanac372026年10月10日 更新

aikido

無料

Practice aikido as a defensive martial art emphasizing harmony, redirection, and controlled resolution. Covers centering and grounding, ukemi (safe falling and rolling), core techniques (irimi-nage, shiho-nage, kote-gaeshi, ikkyo), blending and tai sabaki (body movement), randori (multiple attacker practice), weapons awareness, and applying principles off the mat. Use when learning a defensive martial art that prioritizes de-escalation, developing the ability to redirect aggression without causing unnecessary harm, building safe falling skills, or cultivating calm centeredness under physical pressure.

日本語の概要は準備中です。原文の説明を表示しています。

pjt222/agent-almanac372026年10月10日 更新

Analyze an arbitrary codebase to identify functions, APIs, and data sources suitable for exposure as MCP tools, producing a tool specification document. Use when planning an MCP server for an existing project, auditing a codebase before wrapping it as an AI-accessible tool surface, comparing what a codebase can do versus what is already exposed via MCP, or generating a tool spec to hand off to scaffold-mcp-server.

日本語の概要は準備中です。原文の説明を表示しています。

pjt222/agent-almanac372026年10月10日 更新

pjt222 のスキルをすべて見る

このスキルの問題を報告する