|
| 1 | +# Local Docker deployment |
| 2 | + |
| 3 | +- **Status:** Draft |
| 4 | +- **Last Updated:** 2025-12-11 |
| 5 | +- **Related:** |
| 6 | + |
| 7 | +## 1. Goal |
| 8 | + |
| 9 | +Run Oar as a Docker container on your local machine with persistent data storage. This guide covers building the image, starting the container, and verifying everything works. |
| 10 | + |
| 11 | +## 2. Prerequisites |
| 12 | + |
| 13 | +- **Docker Engine** installed and running (version 20.10 or later) |
| 14 | +- Terminal access with Docker CLI available |
| 15 | +- Access to the Oar project root directory |
| 16 | + |
| 17 | +Verify Docker is available: |
| 18 | + |
| 19 | +```bash |
| 20 | +docker --version |
| 21 | +``` |
| 22 | + |
| 23 | +## 3. Step-by-step guide |
| 24 | + |
| 25 | +### Step 1: Build the Docker image |
| 26 | + |
| 27 | +Navigate to the project root and build the image: |
| 28 | + |
| 29 | +```bash |
| 30 | +docker build -t oar . |
| 31 | +``` |
| 32 | + |
| 33 | +This reads the `Dockerfile` and creates an image tagged `oar`. Build time depends on your network speed and system resources. |
| 34 | + |
| 35 | +**Expected output:** The build completes with `Building 45.1s (23/23) FINISHED` (example). |
| 36 | + |
| 37 | +### Step 2: Run the container |
| 38 | + |
| 39 | +Start Oar with a persistent data volume: |
| 40 | + |
| 41 | +```bash |
| 42 | +docker run -d \ |
| 43 | + -p 8080:8080 \ |
| 44 | + -v oar_data:/app/data \ |
| 45 | + -e DATABASE_URL="./data/oar.db" \ |
| 46 | + --name oar_app \ |
| 47 | + oar |
| 48 | +``` |
| 49 | + |
| 50 | +**Flag breakdown:** |
| 51 | + |
| 52 | +| Flag | Purpose | |
| 53 | +|------|---------| |
| 54 | +| `-d` | Run in detached mode (background) | |
| 55 | +| `-p 8080:8080` | Map host port 8080 to container port 8080 | |
| 56 | +| `-v oar_data:/app/data` | Mount a named volume for SQLite persistence | |
| 57 | +| `-e DATABASE_URL` | Set the database file location | |
| 58 | +| `--name oar_app` | Assign a memorable container name | |
| 59 | + |
| 60 | +**Expected output:** Docker returns the container ID (a long hexadecimal string). |
| 61 | + |
| 62 | +### Step 3: Verify the container is running |
| 63 | + |
| 64 | +Check container status: |
| 65 | + |
| 66 | +```bash |
| 67 | +docker ps |
| 68 | +``` |
| 69 | + |
| 70 | +You should see `oar_app` listed with status `Up`. |
| 71 | + |
| 72 | +## 4. Configuration |
| 73 | + |
| 74 | +### Environment variables |
| 75 | + |
| 76 | +| Variable | Default | Description | |
| 77 | +|----------|---------|-------------| |
| 78 | +| `DATABASE_URL` | `./data/oar.db` | Path to the SQLite database file | |
| 79 | +| `PORT` | `8080` | Port the application listens on | |
| 80 | + |
| 81 | +### Data persistence |
| 82 | + |
| 83 | +The named volume `oar_data` stores your SQLite database. Removing the container does not delete this volume. Your data persists across container restarts and rebuilds. |
| 84 | + |
| 85 | +To delete data permanently: |
| 86 | + |
| 87 | +```bash |
| 88 | +docker volume rm oar_data |
| 89 | +``` |
| 90 | + |
| 91 | +## 5. Verification |
| 92 | + |
| 93 | +Open your browser and navigate to: |
| 94 | + |
| 95 | +``` |
| 96 | +http://localhost:8080 |
| 97 | +``` |
| 98 | + |
| 99 | +You should see the Oar dashboard. Create a test bill to confirm database writes work correctly. |
| 100 | + |
| 101 | +**Container logs check:** |
| 102 | + |
| 103 | +```bash |
| 104 | +docker logs oar_app |
| 105 | +``` |
| 106 | + |
| 107 | +Look for startup messages indicating the server is listening on port 8080. |
| 108 | + |
| 109 | +## 6. Troubleshooting |
| 110 | + |
| 111 | +### Port already in use |
| 112 | + |
| 113 | +**Error:** `bind: address already in use` |
| 114 | + |
| 115 | +**Fix:** Another process occupies port 8080. Either stop that process or use a different host port: |
| 116 | + |
| 117 | +```bash |
| 118 | +docker run -d -p 3000:8080 -v oar_data:/app/data --name oar_app oar |
| 119 | +``` |
| 120 | + |
| 121 | +Then access the app at `http://localhost:3000`. |
| 122 | + |
| 123 | +### Container exits immediately |
| 124 | + |
| 125 | +**Symptom:** `docker ps` shows no running container. |
| 126 | + |
| 127 | +**Debug:** Check logs for errors: |
| 128 | + |
| 129 | +```bash |
| 130 | +docker logs oar_app |
| 131 | +``` |
| 132 | + |
| 133 | +Common causes: |
| 134 | +- Missing environment variables |
| 135 | +- Database file permission issues |
| 136 | + |
| 137 | +### Data not persisting |
| 138 | + |
| 139 | +**Symptom:** Bills disappear after container restart. |
| 140 | + |
| 141 | +**Fix:** Ensure you included the `-v oar_data:/app/data` flag. Without it, data lives only in the container's ephemeral filesystem. |
| 142 | + |
| 143 | +### Rebuilding after code changes |
| 144 | + |
| 145 | +Stop and remove the old container, then rebuild: |
| 146 | + |
| 147 | +```bash |
| 148 | +docker stop oar_app |
| 149 | +docker rm oar_app |
| 150 | +docker build -t oar . |
| 151 | +docker run -d -p 8080:8080 -v oar_data:/app/data --name oar_app oar |
| 152 | +``` |
| 153 | + |
| 154 | +Your data persists because the volume remains intact. |
0 commit comments