Docker Development

This guide focuses on setting up a development environment for OpenAlgo using Docker.

Prerequisites

  • Docker Engine

  • Docker Compose

  • Git

Essential .env Changes for Docker Setup

1. Flask Host Configuration

2. WebSocket Configuration

3. ZeroMQ Configuration

Summary of Changes

From (Local Development):

To (Docker):

Why These Changes?

  1. 0.0.0.0 vs 127.0.0.1:

    • 127.0.0.1 only allows connections from within the container

    • 0.0.0.0 allows connections from outside the container (host machine)

  2. WEBSOCKET_URL:

    • Remains as ws://localhost:8765 because this is the URL clients use from the host machine

    • Docker maps the container's port to the host's localhost

  3. No other changes needed:

    • All other settings (API keys, database URLs, etc.) remain the same

    • The docker-compose.yaml already maps the ports correctly

Files Required

1. Dockerfile

2. docker-compose.yml

3. .dockerignore

Quick Start

  1. Create Environment File:

    Copy .sample.env to .env:

  2. Build and Start:

  3. View Logs:

Development Features

  • Hot reload enabled (code changes reflect immediately)

  • Debug mode active

  • Console logging

  • Port 5000 exposed

  • Volume mounting for live code updates

Common Commands

Directory Structure

Development Tips

  1. Live Reload:

    • Code changes will automatically reload

    • Check logs for errors after changes

  2. Database Access:

    • SQLite database persists in ./db directory

    • Can be accessed from both host and container

  3. Debugging:

    • Logs are printed to console

    • Debug mode enables detailed error pages

  4. Dependencies:

    • Add new packages to requirements-nginx.txt

    • Rebuild container after adding dependencies:

Troubleshooting

  1. Port Already In Use:

  2. Database Issues:

  3. Container Won't Start:

  4. Package Installation Issues:

Note

This configuration is optimized for development. For production deployment, additional security measures and optimizations would be necessary.

Last updated

Was this helpful?