Deploy Prefect in a container, on a remote VM

Objective

I need to deploy Prefect in a container, on a remote Virtual Machine, while being able to access the UI from any computer on the same network.

Where I am

I’ve successfully deployed a container with Prefect on said VM, and it seems I have partial access to the UI from the other machines.
To deploy Prefect, I’ve used

docker run \
  --name prefect \
  --env PREFECT_ORION_API_HOST=0.0.0.0 \
  -v ~/containers/prefect/deployments:/deployments \
  -p 4200:4200 \
  -d prefecthq/prefect:2-latest \
  prefect orion start

Once this command is executed (and a couple seconds given to Orion to boot) then I am able to access the UI at <VM_ip_address>:4200 from my computer.

Issue

While I can access the UI, I still have an error message Can't connect to Orion API at http://0.0.0.0:4200/api. Check that it's accessible from your machine.
Additionally, whatever deployment or run might be executed on the container, nothing is appearing on the interface. (This should be caused by the inaccessibility of the Orion API, if I understood the architecture correctly)

In this situation, how can I parameterize my Prefect container and/or Orion API to allow for the architecture needed?
Thanks a lot

1 Like

Have you tried Prefect Cloud? there is a free version (not a trial) and the networking setup is much easier this way https://app.prefect.cloud/

alternatively, try this:

https://discourse.prefect.io/t/running-prefect-2-with-docker-compose/1516

Thanks, but I cannot use any cloud services.

I will try this and let you know

I’ve just tried this method and there were no improvements to the situation. I still have the same error message.

Additionally, after running the orion, minio and agent profiles, I can’t seem to run any python code as demonstrated in the README (with the CLI). Whatever the code is, I get a HTTP Error 503: Service Unavailable with regards to http://orion:4200/api/health.
I have no idea how to solve this issue.

Did you follow the docker-compose as described or did you change sth? it should just work with a single command

what’s your OS? where and how do you run it?

can you take it more step by step to see at which step something breaks in your setup?

I am on Debian 11 (Bullseye), but the VM on which I intend to run Prefect is on AlmaLinux 8.7 (Stone Smilodon).

I followed the github README.md and I don’t find any one liner here?

When it comes to the step-by-step, the Orion API and UI have been deployed without errors, but accessing the address <VM's ip>:4200 from another machine, while displaying the interface, also returns the Can't connect to Orion API error. Additionally, the interface doesn’t seem functional for there are things missing (nothing in the Blocks tab, etc.)
The agent deployment happens without issue.
Executing the python flow.py command in the CLI yields the HTTP Error 503: Service Unavailable.

I hope this helps

what do you mean?

I don’t know how to help since serving UI is not my area. Maybe you can try helm if self hosting in Docker doesn’t work for you?

By “single liner”, I mean this:

I did not find a command in the README that is supposed to handle everything.

Additionally, I’ve tried Helm, and the same errors appeared.

docker-compose --profile orion up

there is no need to run Orion in Docker, though - you can start everything you need with just prefect orion start - it already includes the UI

I fully agree that Docker and K8s add significant overhead in getting started and this can be avoided if you run Orion directly in a local process, e.g. in a virtual environment

Ok, to me this was only the first step, as we need to setup agents etc.

The goal here was to deploy a Prefect environment in a container (in the same fashion as Airflow can be). This is in order to compare the usage of Airflow and Prefect to maybe switch to Prefect as a solution.

for sure. give it a try and see which option and deployment method you like most. conda is the easiest to get started

I’d love to, but I am unable to use it! And have no idea how to make it.

Your recommendation would then be to deploy a container with conda in it, and start a classical prefect service while exposing the container’s relevant ports?

no need for conda in a container

to run orion in container, try:

docker run -p 4200:4200 prefecthq/prefect:2-latest prefect orion start --host 0.0.0.0

Using this command, and connecting to the UI, I get a Can't connect to Orion API at http://127.0.0.1:4200/api. Check that it's accessible from your machine error.
The container is located on a remote virtual machine, and I canno’t seem to understand how the services are supposed to be organized/where they are located with this command.

right, you would need to then do:

prefect config set PREFECT_API_URL = "http://0.0.0.0:4200/api"

After verification, this seems to be equivalent to my first command:

Being equivalent, these two method yield the same result, the Can't connect to Orion API at http://0.0.0.0:4200/api. Check that it's accessible from your machine. error.