スキル一覧に戻る

create-r-dockerfile

pjt222
更新日 Yesterday
6 閲覧
17
2
17
GitHubで表示
メタaimcpdesign

について

このスキルは、rockerベースイメージを使用してRプロジェクトのDockerfileを生成します。システム依存関係の処理、Rパッケージのインストール、renv統合に対応し、高速なリビルドのためのレイヤー順序を最適化します。Rアプリケーションのコンテナ化、再現可能な環境の構築、ShinyやPlumberなどのRベースサービスのデプロイ時にご利用ください。

クイックインストール

Claude Code

推奨
メイン
npx skills add pjt222/agent-almanac -a claude-code
プラグインコマンド代替
/plugin add https://github.com/pjt222/agent-almanac
Git クローン代替
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/create-r-dockerfile

このコマンドをClaude Codeにコピー&ペーストしてスキルをインストールします

ドキュメント

Create R Dockerfile

Build Dockerfile for R projects using rocker base images. Proper dependency management.

When Use

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

Inputs

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

Steps

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

Got: Base image picked matches project's needs. No extra bloat.

If fail: Unsure which image to use? Start with rocker/r-ver (minimal), add packages as needed. Check rocker-org for 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"]

Got: Dockerfile builds fine with docker build -t myproject .

If fail: Build fails during apt-get install? Check package names for target distro (Debian). renv::restore() fails? Confirm renv.lock and renv/activate.R copied before restore step.

Step 3: Create .dockerignore

.git
.Rproj.user
.Rhistory
.RData
renv/library
renv/cache
renv/staging
docs/
*.tar.gz

Got: .dockerignore drops Git history, IDE files, local renv library, build artifacts from Docker context.

If fail: Docker build still copies unwanted files? Verify .dockerignore in same dir as Dockerfile. Check glob patterns.

Step 4: Build and Test

docker build -t r-project:latest .
docker run --rm -it r-project:latest R -e "sessionInfo()"

Got: Container starts with right R version and all packages available. sessionInfo() output confirms R version.

If fail: Check build logs for system dependency errors. Add missing -dev packages to 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"]

Got: Multi-stage build makes smaller final image. Runtime stage has only compiled R packages, no build tools.

If fail: Packages fail to load in runtime stage? Confirm library path in COPY --from=builder matches where R installed packages. Check with R -e ".libPaths()" in both stages.

Checks

  • docker build finishes without errors
  • Container starts and R session works
  • All required packages available
  • .dockerignore drops unneeded files
  • Image size reasonable for use case
  • Rebuilds fast when only code changes (layer caching works)

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

See Also

  • 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

GitHub リポジトリ

pjt222/agent-almanac
パス: i18n/caveman/skills/create-r-dockerfile
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

関連スキル

content-collections

メタ

このスキルは、Content Collections(Markdown/MDXファイルを型安全なデータコレクションに変換するTypeScriptファーストのツール)の本番環境でテストされた設定を提供します。Zodバリデーションによる型安全性を実現し、ブログ、ドキュメントサイト、コンテンツ重視のVite + Reactアプリケーション構築時にご利用ください。Viteプラグインの設定、MDXコンパイルから、デプロイ最適化、スキーマバリデーションまで、すべてを網羅しています。

スキルを見る

polymarket

メタ

このスキルは、開発者がPolymarket予測市場プラットフォームを活用したアプリケーション構築を可能にします。API統合による取引や市場データの取得に加え、WebSocketを介したリアルタイムデータストリーミングにより、ライブ取引や市場活動を監視できます。取引戦略の実装や、ライブ市場更新を処理するツールの作成にご利用ください。

スキルを見る

creating-opencode-plugins

メタ

このスキルは、開発者がコマンド、ファイル、LSP操作など25種類以上のイベントタイプにフックするOpenCodeプラグインを作成することを支援します。JavaScript/TypeScriptモジュール向けに、プラグイン構造、イベントAPI仕様、および実装パターンを提供します。カスタムイベント駆動ロジックでOpenCode AIアシスタントのライフサイクルをインターセプト、監視、または拡張する必要がある場合にご利用ください。

スキルを見る

sglang

メタ

SGLangは、高性能なLLMサービングフレームワークであり、RadixAttentionプレフィックスキャッシュを活用したJSON、正規表現、エージェントワークフロー向けの高速で構造化された生成を特長とします。特にプレフィックスが繰り返されるタスクにおいて、大幅に高速な推論を実現し、複雑な構造化出力やマルチターン対話に最適です。制約付きデコードが必要な場合や、広範なプレフィックス共有を伴うアプリケーションを構築する場合は、vLLMなどの代替案ではなくSGLangを選択してください。

スキルを見る