writing-skills
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
setup-docker-composeConfigure Docker Compose for multi-container R development environments. Covers service definitions, volume mounts, networking, environment variables, and dev vs production configurations. Use to run R alongside other services (databases, APIs), set up a reproducible R dev environment, orchestrate an R-based MCP server container, or manage environment varia…
Independent GitHub snapshot · Automated classification · Original documentation governs
Configure Docker Compose for R development and deployment environments.
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
Got: A docker-compose.yml file with the R service defined, including volume mounts for the project directory and renv cache, and environment variables for R library paths.
If fail: With invalid YAML, validate using docker compose config. Ensure indentation uses spaces (not tabs) and all string values with special characters are quoted.
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:
Got: The additional service (e.g., PostgreSQL) is defined with its own volume, environment variables, and port mapping. The R service has depends_on referencing the new service.
If fail: If the database service fails to start, check docker compose logs postgres for initialization errors. Verify that environment variables like POSTGRES_PASSWORD_FILE point to valid secrets or switch to POSTGRES_PASSWORD for development.
For services that need localhost access (e.g., MCP servers):
services:
r-dev:
network_mode: "host"
For isolated networking:
services:
r-dev:
networks:
- app-network
ports:
- "3000:3000"
networks:
app-network:
driver: bridge
Got: Networking configured appropriately: host mode for services needing localhost access (MCP servers), or bridge networking with explicit port mappings for isolated services.
If fail: If services cannot communicate, verify they are on the same network. With bridge networking, use service names as hostnames (e.g., postgres not localhost). With host mode, use localhost and ensure ports do not conflict.
Create .env file (git-ignored):
R_VERSION=4.5.0
GITHUB_PAT=your_token_here
Reference in compose:
services:
r-dev:
build:
args:
R_VERSION: ${R_VERSION}
env_file:
- .env
Got: A .env file (git-ignored) with project-specific variables, and docker-compose.yml references it via env_file or variable interpolation (${VAR}).
If fail: If variables are not resolving, ensure the .env file is in the same directory as docker-compose.yml. Run docker compose config to see the resolved configuration with all variables expanded.
# 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
Got: All services start. R session accessible.
If fail: Check docker compose logs for startup errors. Common: port conflicts, missing environment variables.
Create docker-compose.override.yml for local development settings:
services:
r-dev:
volumes:
- /path/to/local/packages:/extra-packages
environment:
- DEBUG=true
This is automatically merged with docker-compose.yml.
Got: A docker-compose.override.yml file with development-specific settings (extra volumes, debug flags) automatically applied when running docker compose up.
If fail: If overrides are not taking effect, verify the filename is exactly docker-compose.override.yml. Run docker compose config to confirm the merge. For explicit override files, use docker compose -f docker-compose.yml -f custom-override.yml up.
docker compose build completes without errorsdocker compose up starts all servicesdocker compose down cleanly stops everythinguser: directive or fix permissions.docker compose (v2) vs docker-compose (v1). Use v2./mnt/c/... paths when mounting Windows directories from WSLcreate-r-dockerfile - create the Dockerfile that compose referencescontainerize-mcp-server - compose configuration for MCP serversoptimize-docker-build-cache - speed up compose builds