Docker Support
Docker provides a lightweight and isolated environment to run OpenCode, making it ideal for DevOps workflows, CI/CD pipelines, and consistent development environments.
Quick Start
The simplest way to run OpenCode in Docker is using the official image:
docker run -it -v $(pwd):/app anomalyco/opencode:latest
This command:
- Runs OpenCode in interactive mode (
-it) - Mounts the current directory (
$(pwd)) to/appin the container - Uses the latest version of the OpenCode image
Docker Compose
For more complex setups, you can use Docker Compose. Create a docker-compose.yml file:
version: '3'
services:
opencode:
image: anomalyco/opencode:latest
volumes:
- .:/app
- opencode-config:/root/.config/opencode
working_dir: /app
tty: true
stdin_open: true
volumes:
opencode-config:
Then start the container:
docker-compose up -d
DevOps Integration
CI/CD Pipelines
You can use OpenCode in CI/CD pipelines to automate code reviews and improvements:
docker run --rm -v $(pwd):/app anomalyco/opencode:latest review --auto-apply
Pre-commit Hooks
Integrate OpenCode into your pre-commit workflow:
# .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: opencode-review
name: OpenCode Review
entry: docker run --rm -v $(pwd):/app anomalyco/opencode:latest review
language: system
types: [file]
files: \.(js|ts|py|go|java)$
Configuration
Environment Variables
You can configure OpenCode using environment variables:
docker run -it \
-v $(pwd):/app \
-e OPENCODE_API_KEY=your-api-key \
-e OPENCODE_MODEL=gpt-4 \
anomalyco/opencode:latest
Persistent Configuration
To persist configuration across container runs, mount the configuration directory:
docker run -it \
-v $(pwd):/app \
-v ~/.config/opencode:/root/.config/opencode \
anomalyco/opencode:latest
Advanced Usage
Custom Dockerfile
For more control, create a custom Dockerfile:
FROM anomalyco/opencode:latest
# Install additional dependencies
RUN apt-get update && apt-get install -y git
# Set up custom configuration
COPY opencode.config.json /root/.config/opencode/config.json
WORKDIR /app
Build and run:
docker build -t my-opencode .
docker run -it -v $(pwd):/app my-opencode
Multi-stage Builds
For CI/CD environments, use multi-stage builds to keep your images small:
# Build stage
FROM node:18 as build
WORKDIR /app
COPY . .
RUN npm install && npm run build
# Production stage
FROM anomalyco/opencode:latest
WORKDIR /app
COPY --from=build /app/dist /app/dist
# Run OpenCode analysis
CMD ["opencode", "review", "./dist"]
Troubleshooting
Permission Issues
If you encounter permission issues with mounted volumes:
docker run -it \
-v $(pwd):/app \
-u $(id -u):$(id -g) \
anomalyco/opencode:latest
Network Access
To allow OpenCode to access the internet for API calls:
docker run -it \
--network=host \
-v $(pwd):/app \
anomalyco/opencode:latest
Best Practices
- Use specific image tags instead of
latestfor reproducible builds - Mount only necessary directories to improve performance
- Use Docker Compose for complex setups with multiple services
- Configure resource limits for production environments
- Implement health checks for container orchestration
Supported Tags
The OpenCode Docker image is available with the following tags:
latest: Latest stable releasevX.Y.Z: Specific version (e.g.,v1.0.0)dev: Development builds
Example: GitLab CI Integration
# .gitlab-ci.yml
stages:
- code-review
opencode-review:
stage: code-review
image: anomalyco/opencode:latest
script:
- opencode review --auto-apply
only:
- merge_requests
artifacts:
paths:
- opencode-report.json
Example: GitHub Actions Integration
# .github/workflows/opencode-review.yml
name: OpenCode Review
on:
pull_request:
branches: [ main ]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run OpenCode Review
run: |
docker run --rm -v $(pwd):/app anomalyco/opencode:latest review --auto-apply
- name: Upload report
uses: actions/upload-artifact@v3
with:
name: opencode-report
path: opencode-report.json