setup-docker-compose
About
This skill configures Docker Compose for multi-container R development environments, handling service definitions, volumes, networking, and environment variables. Use it when running R alongside databases or APIs, or to create reproducible development setups. It helps orchestrate R-based services and manage development versus production configurations.
Quick Install
Claude Code
Recommendednpx 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/setup-docker-composeCopy and paste this command in Claude Code to install this skill
Documentation
設 Docker Compose
為 R 多容開發與展之境配 Docker Compose。
用時
- R 與他服(庫、API)並行乃用
- 設可重之開發境乃用
- 為 R 之 MCP 服容編排乃用
- 管環境變與卷掛乃用
入
- 必要:R 服之 Dockerfile
- 必要:所掛之項目目
- 可選:他服(庫、緩、網服)
- 可選:環境變之配
法
第一步:立 docker-compose.yml
version: '3.8'
services:
r-dev:
build:
context: .
dockerfile: Dockerfile
container_name: r-dev
image: r-dev:latest
volumes:
- .:/workspace
- renv-cache:/workspace/renv/cache
stdin_open: true
tty: true
environment:
- TERM=xterm-256color
- R_LIBS_USER=/workspace/renv/library
- RENV_PATHS_CACHE=/workspace/renv/cache
command: R
restart: unless-stopped
volumes:
renv-cache:
driver: local
得:docker-compose.yml 存附 R 服之定,含項目目與 renv 緩之卷掛、與 R 庫徑之環境變。
敗則:YAML 語法誤,以 docker compose config 驗。確縮以空(非 tab),含特字之串值皆引。
第二步:增他服(若需)
services:
r-dev:
# ... as above
depends_on:
- postgres
environment:
- DB_HOST=postgres
- DB_PORT=5432
postgres:
image: postgres:16
container_name: r-postgres
environment:
POSTGRES_DB: analysis
POSTGRES_USER: ruser
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "5432:5432"
volumes:
renv-cache:
pgdata:
得:他服(如 PostgreSQL)已定附其卷、環境變、端映。R 服有 depends_on 指新服。
敗則:庫服啟敗,察 docker compose logs postgres 之初誤。驗 POSTGRES_PASSWORD_FILE 等指有效之密,或為開發改 POSTGRES_PASSWORD。
第三步:配網
為需 localhost 之服(如 MCP 服):
services:
r-dev:
network_mode: "host"
為隔之網:
services:
r-dev:
networks:
- app-network
ports:
- "3000:3000"
networks:
app-network:
driver: bridge
得:網配宜:host 模為需 localhost 之服(MCP 服),或橋網附明端映為隔之服。
敗則:服不能通,驗皆於同網。橋網用服名為主機名(如 postgres,非 localhost)。host 模用 localhost 確端口無衝。
第四步:管環境變
立 .env 文件(git-ignored):
R_VERSION=4.5.0
GITHUB_PAT=your_token_here
於 compose 引:
services:
r-dev:
build:
args:
R_VERSION: ${R_VERSION}
env_file:
- .env
得:.env 文件存(git-ignored)附項目特之變,docker-compose.yml 引之以 env_file 或變插(${VAR})。
敗則:變不解,確 .env 與 docker-compose.yml 同目。行 docker compose config 觀解後之配。
第五步:建而行
# Build images
docker compose build
# Start services
docker compose up -d
# Attach to R session
docker compose exec r-dev R
# View logs
docker compose logs -f r-dev
# Stop services
docker compose down
得:諸服啟。R 會話可訪。
敗則:察 docker compose logs 之啟誤。常患:端口衝、缺環境變。
第六步:為開發立 override
立 docker-compose.override.yml 為本地開發設:
services:
r-dev:
volumes:
- /path/to/local/packages:/extra-packages
environment:
- DEBUG=true
此自合於 docker-compose.yml。
得:docker-compose.override.yml 存附開發特之設(額卷、調試旗),自施於 docker compose up。
敗則:override 不效,驗文名確為 docker-compose.override.yml。行 docker compose config 確合。明 override 文件用 docker compose -f docker-compose.yml -f custom-override.yml up。
驗
-
docker compose build成而無誤 -
docker compose up啟諸服 - 卷掛正共文件於主與容
- 環境變於容內可得
- 諸服可相通
-
docker compose down潔止諸物
陷
- 卷掛之權:Linux 容或以 root 立文件。用
user:指或修權 - 端口衝:察主上既用同端之服
- Docker Desktop vs CLI:
docker compose(v2)vsdocker-compose(v1)。用 v2 - WSL 徑掛:自 WSL 掛 Windows 目用
/mnt/c/...徑 - 命名卷 vs 綁掛:命名卷跨重建持;綁掛即映主之變
參
create-r-dockerfile— 立 compose 所引之 Dockerfilecontainerize-mcp-server— MCP 服之 compose 配optimize-docker-build-cache— 速 compose 之建
GitHub Repository
Related Skills
railway-docs
DocumentationThis skill fetches current Railway documentation to answer questions about features, functionality, or specific docs URLs. It ensures developers receive accurate, up-to-date information directly from Railway's official sources. Use it when users ask how Railway works or reference Railway documentation.
n8n-code-python
DocumentationThis Claude Skill provides expert guidance for writing Python code in n8n's Code nodes, specifically for using Python's standard library and working with n8n's special syntax like `_input`, `_json`, and `_node`. It helps developers understand Python's limitations within n8n and recommends using JavaScript for most workflows while offering Python solutions for specific data transformation needs.
archon
DocumentationThe Archon skill provides RAG-powered semantic search and project management through a REST API. Use it for querying documentation, managing hierarchical projects/tasks, and performing knowledge retrieval with document upload capabilities. Always prioritize Archon first when searching external documentation before using other sources.
n8n-code-javascript
DocumentationThis Claude Skill provides expert guidance for writing JavaScript code in n8n's Code nodes. It covers essential n8n-specific syntax like `$input`/`$json` variables, HTTP helpers, and DateTime handling, while troubleshooting common errors. Use it when developing n8n workflows that require custom JavaScript processing in Code nodes.
