|
| 1 | +--- |
| 2 | +title: Setup |
| 3 | +--- |
| 4 | + |
| 5 | +# Prefect Server Setup |
| 6 | + |
| 7 | +This guide walks through setting up the Prefect server for the first time on a |
| 8 | +host that already has Docker and Docker Compose installed. |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +- Docker Engine and **Docker Compose v2** installed on the host machine. |
| 13 | +- The OpticStream source repository cloned on the host (see [Installation](installation.md)). |
| 14 | +- Network access to the host from any machine that will use the Prefect UI or |
| 15 | + submit flows (if running remotely). |
| 16 | + |
| 17 | +## 1. Configure the server URL |
| 18 | + |
| 19 | +The `docker-compose.yaml` in the repository root uses a `HOST_IP` variable to |
| 20 | +set the Prefect API and UI URLs. By default it falls back to `127.0.0.1`, which |
| 21 | +only allows access from the Docker host itself. |
| 22 | + |
| 23 | +If you need to reach the Prefect UI or API from **other machines on the |
| 24 | +network** (e.g. workers or browsers on different hosts), set `HOST_IP` to the |
| 25 | +host's LAN IP address or resolvable hostname. |
| 26 | + |
| 27 | +### Option A — create a `.env` file (recommended) |
| 28 | + |
| 29 | +Copy the provided example and edit the IP: |
| 30 | + |
| 31 | +```bash |
| 32 | +cd opticstream # repository root |
| 33 | +cp .env.example .env |
| 34 | +``` |
| 35 | + |
| 36 | +Then open `.env` and replace the default value: |
| 37 | + |
| 38 | +```dotenv |
| 39 | +# Use the host's LAN IP so other machines can reach the Prefect server. |
| 40 | +# Use 127.0.0.1 if you only access the server from the Docker host. |
| 41 | +HOST_IP=192.168.1.100 |
| 42 | +``` |
| 43 | + |
| 44 | +Docker Compose automatically loads `.env` from the same directory as the |
| 45 | +compose file, so no extra flags are needed. |
| 46 | + |
| 47 | +### Option B — export the variable in your shell |
| 48 | + |
| 49 | +```bash |
| 50 | +export HOST_IP=192.168.1.100 |
| 51 | +``` |
| 52 | + |
| 53 | +This is useful for one-off launches or CI environments where you don't want a |
| 54 | +persisted `.env` file. |
| 55 | + |
| 56 | +### What the variable controls |
| 57 | + |
| 58 | +Inside `docker-compose.yaml`, the `server` service references `HOST_IP` in two |
| 59 | +environment variables: |
| 60 | + |
| 61 | +```yaml |
| 62 | +- PREFECT_UI_URL=http://${HOST_IP:-127.0.0.1}:4200/api |
| 63 | +- PREFECT_API_URL=http://${HOST_IP:-127.0.0.1}:4200/api |
| 64 | +``` |
| 65 | +
|
| 66 | +`PREFECT_API_URL` tells Prefect clients where to send API requests, and |
| 67 | +`PREFECT_UI_URL` tells the browser-based dashboard where to find the API |
| 68 | +backend. Both must be reachable from whatever machine is connecting. |
| 69 | + |
| 70 | +## 2. Start the Prefect server |
| 71 | + |
| 72 | +From the repository root, bring up the server profile (which starts the |
| 73 | +PostgreSQL database and the Prefect server): |
| 74 | + |
| 75 | +```bash |
| 76 | +docker compose --profile server up -d |
| 77 | +``` |
| 78 | + |
| 79 | +This pulls the required images on first run (`postgres:alpine` and |
| 80 | +`prefecthq/prefect:3-python3.12`), creates the `prefect-network` Docker |
| 81 | +network, and starts both containers in detached mode. |
| 82 | + |
| 83 | +### Verify the services are running |
| 84 | + |
| 85 | +```bash |
| 86 | +docker compose --profile server ps |
| 87 | +``` |
| 88 | + |
| 89 | +You should see two containers (`database` and `server`) with status **Up**. |
| 90 | + |
| 91 | +Check the server logs to confirm a healthy start: |
| 92 | + |
| 93 | +```bash |
| 94 | +docker compose --profile server logs server |
| 95 | +``` |
| 96 | + |
| 97 | +Look for a line similar to: |
| 98 | + |
| 99 | +``` |
| 100 | +Configure Prefect to communicate with the server with: |
| 101 | +
|
| 102 | + prefect config set PREFECT_API_URL=http://…:4200/api |
| 103 | +``` |
| 104 | + |
| 105 | +## 3. Open the Prefect dashboard |
| 106 | + |
| 107 | +In a browser, navigate to: |
| 108 | + |
| 109 | +``` |
| 110 | +http://<HOST_IP>:4200 |
| 111 | +``` |
| 112 | + |
| 113 | +Replace `<HOST_IP>` with the value you configured (or `127.0.0.1` / `localhost` |
| 114 | +if accessing from the Docker host). You should see the Prefect UI dashboard. |
| 115 | + |
| 116 | +## 4. Point local clients at the server |
| 117 | + |
| 118 | +On any machine that will submit or monitor flows, tell Prefect where the server |
| 119 | +lives: |
| 120 | + |
| 121 | +```bash |
| 122 | +prefect config set PREFECT_API_URL=http://<HOST_IP>:4200/api |
| 123 | +``` |
| 124 | + |
| 125 | +Or set it as an environment variable in your shell: |
| 126 | + |
| 127 | +```bash |
| 128 | +export PREFECT_API_URL=http://<HOST_IP>:4200/api |
| 129 | +``` |
| 130 | + |
| 131 | +You can verify the connection with: |
| 132 | + |
| 133 | +```bash |
| 134 | +prefect version # prints client version |
| 135 | +prefect server health # should return healthy |
| 136 | +``` |
| 137 | + |
| 138 | +## 5. Stopping and restarting |
| 139 | + |
| 140 | +Stop the server (containers are removed but volumes persist): |
| 141 | + |
| 142 | +```bash |
| 143 | +docker compose --profile server down |
| 144 | +``` |
| 145 | + |
| 146 | +Restart later with the same command used to start: |
| 147 | + |
| 148 | +```bash |
| 149 | +docker compose --profile server up -d |
| 150 | +``` |
| 151 | + |
| 152 | +All flow-run history and configuration is stored in the `db` Docker volume and |
| 153 | +survives restarts. |
| 154 | + |
| 155 | +## Troubleshooting |
| 156 | + |
| 157 | +| Symptom | Likely cause | Fix | |
| 158 | +|---|---|---| |
| 159 | +| Browser cannot reach `http://<HOST_IP>:4200` | `HOST_IP` is wrong or firewall blocks port 4200 | Verify `HOST_IP` matches the host's actual LAN IP; open port 4200 in the firewall | |
| 160 | +| `prefect server health` fails from another machine | `PREFECT_API_URL` on the client doesn't match `HOST_IP` | Re-run `prefect config set PREFECT_API_URL=…` with the correct address | |
| 161 | +| Database connection errors in server logs | The `database` container isn't running | Run `docker compose --profile server up -d` and check `docker compose --profile server ps` | |
| 162 | +| Containers exit immediately | Port 4200 or 5432 already in use on the host | Stop the conflicting service or change the port mapping in `docker-compose.yaml` | |
| 163 | + |
| 164 | +## Next steps |
| 165 | + |
| 166 | +- Continue with the [Quickstart](quickstart.md) to configure a scan and run |
| 167 | + your first flow. |
| 168 | +- See [Configuration](configuration.md) for scan and project settings. |
0 commit comments