Docker
Learn how to run moclojer with Docker. Official images, Docker Compose, volumes, networks and production-ready deployment.
moclojer offers official Docker images to simplify deployment and development. This guide shows how to use Docker and Docker Compose to run your mock server.
Why Use Docker?
✅ Isolation: Consistent environment on any machine ✅ Portability: Works in dev, staging and production ✅ Easy deployment: Pull, run, done! ✅ Versioning: Lock specific versions ✅ CI/CD: Easy integration with pipelines
Official Image
Repository
ghcr.io/moclojer/moclojer:latestAvailable tags:
latest- Latest stable versionv0.4.0- Specific versionmain- Build from main branch (bleeding edge)
Check Version
docker run --rm ghcr.io/moclojer/moclojer:latest --versionQuick Start
1. Create Configuration File
Create moclojer.yml:
2. Run with Docker
3. Test
🎉 It works!
Bind Mount vs Volume
Bind Mount (Development)
Advantages: Edit local file, changes reflect immediately
With --watch: Automatically reloads when file changes!
Named Volume (Production)
Docker Compose
Basic Setup
Create docker-compose.yml:
Run:
Run in background:
View logs:
Stop:
With Hot-Reload (Dev)
With Environment Variables
Create .env:
Run:
With Health Check
Check status:
External Bodies with Global Configuration
When using external body files in Docker, you can leverage the global folder configuration to simplify your setup. This is especially useful when mounting volumes with response data.
Setup
1. Create directory structure:
2. Configure moclojer.yml with global folder:
3. docker-compose.yml:
4. Run:
Benefits
✅ Clean configuration: No repeated paths ✅ Easy updates: Update JSON files without changing config ✅ Volume management: Single mount point for all data ✅ Team collaboration: Clear separation between config and data
Testing
See Example
Full working example available at: examples/external-body-global/
Multiple Environments
File Structure
docker-compose.yml
.env files
.env.dev:
.env.staging:
.env.prod:
Run:
Networking
With Other Services
Application accesses: http://moclojer:8000/api/users
Custom Network
CI/CD Integration
GitHub Actions
GitLab CI
Docker Compose in CI
docker-compose.ci.yml:
Production
docker-compose.prod.yml
Deploy:
With Nginx Reverse Proxy
nginx.conf:
Troubleshooting
Container won't start
Problem: docker: Error response from daemon: Conflict
Solution: Remove old container
Config file not found
Problem: Config file not found
Solution: Check mount
Port already in use
Problem: Bind for 0.0.0.0:8000 failed: port is already allocated
Solution: Change host port
Hot-reload not working
Problem: File changes don't reload
Causes:
Didn't pass
--watchUsing native image (GraalVM) - doesn't support watch
Solution:
Volume permissions
Problem: Permission denied
Solution: Adjust permissions
Best Practices
✅ Do
Use fixed versions in production
Read-only volumes when possible
Health checks
Resource limits
Configure logging
❌ Avoid
:latestin productionRunning as root (if possible, use USER in Dockerfile)
Exposing unnecessary ports
Volumes without :ro when write is not needed
Complete Examples
E2E Testing Setup
Run tests:
Next Steps
Kubernetes Deployment - Deploy to K8s
Cloud Run - Deploy to Google Cloud
CI/CD Integration - Continuous integration
See Also
CLI Reference - Flags and options
Troubleshooting Guide - Common issues
Last updated
Was this helpful?