If you’d like to run Prefect 2 using Docker Compose, I have created a sample repository that will help you get started. It contains a Docker Compose file and instructions that will help you run Prefect Orion, a Prefect agent, or the Prefect CLI. You can find it here:
If you have any questions or if there are any other examples you would like to see, please feel free to ask!
5 Likes
I was getting a “Can’t connect to Orion API at http://0.0.0.0:4200/api ” error in the UI when trying this method. I could connect on the same machine/VM but the UI stopped working as soon as I tried to access it on another machine.
Had to do quite a lot of digging, and so for anyone with similar problems, the solution was to change the following lines in docker-compose.yml. The important bits is to start orion with the correct host prefect orion start --host 0.0.0.0
and to set up the correct environment variables
### Prefect Orion API
orion:
image: prefecthq/prefect:2.7.1-python3.11
restart: always
volumes:
- prefect:/root/.prefect
entrypoint: ["prefect", "orion", "start", "--host", "0.0.0.0"]
environment:
# - PREFECT_ORION_API_HOST=0.0.0.0
- PREFECT_ORION_API_HOST=127.0.0.1
- PREFECT_ORION_API_PORT=4200
Other links that helped:
These instructions are accurate as of Prefect 2.0b5
Create a VM on Cloud Provider of Choice
Open port 4200 ingress on the VM from 0.0.0.0/0 (all traffic) as well as HTTP in.
pip install prefect 2.0
Set the UI_API_URL with :
prefect config set PREFECT_ORION_UI_API_URL="http://<external-ip>:4200/api"
Start Orion with:
prefect orion start --host 0.0.0.0
From local machine, configure to hit the API with:
prefect config set PREFECT_API_URL="http://<external-ip>:4200/api"
The remote UI will…
opened 10:51AM - 06 Apr 22 UTC
closed 09:51PM - 25 Apr 22 UTC
ui
v2
status:roadmap
## Description
I’m using Prefect 2.0b and I am running it on my dev machine..… I want to access the Orion UI from another machine but it shows me no data because the web app is making API calls to `127.0.0.1:4200` instead of the API URL I set (using `PREFECT_API_URL`) to `0.0.0.0:4200/api`, which fails because the API is listening on the dev machine and not locally on the machine I am accessing Orion from.
I have to self-host and can't use Prefect Cloud (as was suggested to me in your Slack channel)
## Reproduction / Example
```
$ prefect --version
2.0b2
$ prefect orion start
Starting...
___ ___ ___ ___ ___ ___ _____ ___ ___ ___ ___ _ _
| _ \ _ \ __| __| __/ __|_ _| / _ \| _ \_ _/ _ \| \| |
| _/ / _|| _|| _| (__ | | | (_) | /| | (_) | .` |
|_| |_|_\___|_| |___\___| |_| \___/|_|_\___\___/|_|\_|
Configure Prefect to communicate with the server with:
prefect config set PREFECT_API_URL=http://0.0.0.0:4200/api
Check out the dashboard at http://0.0.0.0:4200
```

This Discourse topic is meant to be used as a comprehensive list of resources pointing you to the right documentation or a tutorial. Depending on a different cloud provider or on-premise infrastructure requirements, you may need a different way of deploying Prefect 2.0.
Architecture & components of Prefect 2.0
Self-hosting on a VM with docker-compose
Self-hosting on a Linux VM
Self-hosting on AWS EC2
Docker-compose
Helm chart
Cloud 2.0 as an alternative
…
We appreciate you sharing this!
I’ll make some updates in the repo to cover this scenario. I’m also working on a follow-up that adds an Nginx container for serving requests to other machines.
1 Like
Hi Ryan
Thanks for sharing.
I am able to follow the instructions in the gitub. I run a Prefect Orion on remote VM, and deploy a flow from ‘docker compose run cli’ on the same VM.
But I can’t deploy from a different VM even after I set the PREFECT_API_URL. I got an error:
httpx.HTTPStatusError: Client error ‘422 Unprocessable Entity’ for url ‘http://prefect.private.bridgerinvestment.com:4200/api/deployments/ ’
For more information check: 422 Unprocessable Entity - HTTP Status Code Glossary - WebFX
Do you have any suggestions?
Thanks
qoolfly:
422
The issue looks like to be caused by different prefect version used in remote and local VM. Works fine now.
Hi, qoolfly! Thanks for the update.
Do you know which versions you were running in each location?
1 Like