MCP HubMCP Hub
스킬 목록으로 돌아가기

create-r-dockerfile

pjt222
업데이트됨 Yesterday
3 조회
17
2
17
GitHub에서 보기
메타aimcpdesign

정보

이 Claude 기술은 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 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

Got: A base image is selected that matches the project's requirements without unnecessary bloat.

If fail: 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"]

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

If fail: 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

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

If fail: 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()"

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

If fail: 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"]

Got: Multi-stage build produces a smaller final image. Runtime stage contains only compiled R packages, not build tools.

If fail: 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)

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

GitHub 저장소

pjt222/agent-almanac
경로: i18n/caveman-lite/skills/create-r-dockerfile
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

연관 스킬

content-collections

메타

이 스킬은 콘텐츠 콜렉션(Content Collections)을 위한 프로덕션 검증된 설정을 제공합니다. 콘텐츠 콜렉션은 Markdown/MDX 파일을 Zod 검증이 포함된 타입 안전한 데이터 콜렉션으로 변환해주는 TypeScript 최우선 도구입니다. 블로그, 문서 사이트 또는 콘텐츠 중심의 Vite + React 애플리케이션을 구축할 때 타입 안전성과 자동 콘텐츠 검증을 보장하기 위해 사용하세요. Vite 플러그인 구성과 MDX 컴파일부터 배포 최적화 및 스키마 검증에 이르기까지 모든 것을 다룹니다.

스킬 보기

polymarket

메타

이 스킬은 개발자들이 Polymarket 예측 시장 플랫폼을 활용한 애플리케이션을 구축할 수 있도록 지원하며, 거래 및 시장 데이터를 위한 API 통합 기능을 포함합니다. 또한 WebSocket을 통한 실시간 데이터 스트리밍을 제공하여 실시간 거래와 시장 활동을 모니터링할 수 있습니다. 이를 통해 거래 전략을 구현하거나 실시간 시장 업데이트를 처리하는 도구를 생성하는 데 활용할 수 있습니다.

스킬 보기

creating-opencode-plugins

메타

이 스킬은 개발자들이 명령어, 파일, LSP 작업 등 25개 이상의 이벤트 유형에 연결되는 OpenCode 플러그인을 만들 수 있도록 돕습니다. JavaScript/TypeScript 모듈을 위한 플러그인 구조, 이벤트 API 명세, 구현 패턴을 제공합니다. OpenCode AI 어시스턴트의 라이프사이클을 사용자 정의 이벤트 기반 로직으로 가로채거나, 모니터링하거나, 확장해야 할 때 사용하세요.

스킬 보기

sglang

메타

SGLang은 RadixAttention 프리픽스 캐싱을 활용하여 JSON, 정규식, 에이전트 워크플로우를 위한 고속 구조화 생성에 특화된 고성능 LLM 서빙 프레임워크입니다. 특히 반복되는 프리픽스가 있는 작업에서 상당히 빠른 추론 속도를 제공하여 복잡한 구조화 출력 및 다중 턴 대화에 이상적입니다. 제약 디코딩이 필요하거나 광범위한 프리픽스 공유가 있는 애플리케이션을 구축할 때는 vLLM과 같은 대안보다 SGLang을 선택하십시오.

스킬 보기