关于
This skill generates a Dockerfile for R projects using rocker base images. It handles system dependencies, R package installation, renv integration, and optimizes layer ordering for fast rebuilds. Use it when containerizing R applications, creating reproducible environments, or deploying R-based services like Shiny or Plumber.
快速安装
Claude Code
推荐npx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit 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 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 |
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 buildfinishes without errors - Container starts and R session works
- All required packages available
-
.dockerignoredrops 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
-devlibraries. Check error messages duringinstall.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/*afterapt-get install. Consider multi-stage builds. - Timezone issues: Add
ENV TZ=UTCor installtzdatafor 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 containerscontainerize-mcp-server- special case for MCP R serversoptimize-docker-build-cache- advanced caching strategiesmanage-renv-dependencies- renv.lock feeds into Docker builds
GitHub 仓库
Frequently asked questions
What is the create-r-dockerfile skill?
create-r-dockerfile is a Claude Skill by pjt222. Skills package instructions and resources that Claude loads on demand, so Claude can perform create-r-dockerfile-related tasks without extra prompting.
How do I install create-r-dockerfile?
Use the install commands on this page: add create-r-dockerfile to Claude Code as a plugin, or clone its repository into your skills directory, then restart Claude so it picks up the skill.
What category does create-r-dockerfile belong to?
create-r-dockerfile is in the Meta category, tagged ai, mcp and design.
Is create-r-dockerfile free to use?
Yes. create-r-dockerfile is listed on AIMCP and free to install. It runs inside Claude, so no separate service account is required to use the skill itself.
相关推荐技能
Content Collections 是一个 TypeScript 优先的构建工具,可将本地 Markdown/MDX 文件转换为类型安全的数据集合。它专为构建博客、文档站和内容密集型 Vite+React 应用而设计,提供基于 Zod 的自动模式验证。该工具涵盖从 Vite 插件配置、MDX 编译到生产环境部署的完整工作流。
这个Claude Skill为开发者提供完整的Polymarket预测市场开发支持,涵盖API调用、交易执行和市场数据分析。关键特性包括实时WebSocket数据流,可监控实时交易、订单和市场动态。开发者可用它构建预测市场应用、实施交易策略并集成实时市场预测功能。
该Skill帮助开发者创建OpenCode插件,用于接入命令、文件、LSP等25+种事件。它提供了插件结构、事件API规范和JavaScript/TypeScript实现模式,适合需要拦截操作、扩展功能或自定义事件处理的场景。开发者可通过它快速构建响应式模块来增强OpenCode AI助手的能力。
SGLang是一个专为LLM设计的高性能推理框架,特别适用于需要结构化输出的场景。它通过RadixAttention前缀缓存技术,在处理JSON、正则表达式、工具调用等具有重复前缀的复杂工作流时,能实现极速生成。如果你正在构建智能体或多轮对话系统,并追求远超vLLM的推理性能,SGLang是理想选择。
