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:latest

Available tags:

  • latest - Latest stable version

  • v0.4.0 - Specific version

  • main - Build from main branch (bleeding edge)

Check Version

docker run --rm ghcr.io/moclojer/moclojer:latest --version

Quick 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:

  1. Didn't pass --watch

  2. Using native image (GraalVM) - doesn't support watch

Solution:

Volume permissions

Problem: Permission denied

Solution: Adjust permissions


Best Practices

✅ Do

  1. Use fixed versions in production

  2. Read-only volumes when possible

  3. Health checks

  4. Resource limits

  5. Configure logging

❌ Avoid

  1. :latest in production

  2. Running as root (if possible, use USER in Dockerfile)

  3. Exposing unnecessary ports

  4. Volumes without :ro when write is not needed


Complete Examples

E2E Testing Setup

Run tests:


Next Steps

See Also

Last updated

Was this helpful?