hey, I have a simple py file, I wanna create a sim...
# best-practices
o
hey, I have a simple py file, I wanna create a simple worker to run the py file (all in a docker container) I don't want to create a docker worker, I wanna create a simple worker to run the file inside a docker container, what's the best way to do so?
a
Hey @Omar Hamad! You could use
flow.serve
as a simpler alternative to running a Docker worker. The first two sections of this guide are a good walkthrough of how to do that.
o
i know, but i want to run all of that in a docker container
a
You can build a Docker image that has your script inside and start it as the entrypoint for your image. That will allow you to serve your script so that it will poll for scheduled executions and run your flow when runs are scheduled.
blob attention gif 1
o
Thank you ❤️
I got it
🎉 1
Another question what if i want to create a work pool inside that container and make the script run over this work pool
a
If you use
flow.serve,
you wouldn’t need to create a work pool. Is there something about your use case that requires a work pool?
o
I want to run the code locally and only want to use prefect UI to watch/handle it, I don't want to use prefect servers to run the code
a
Gotcha, that’s still valid with
flow.serve
. The Docker container(s) hosting your server script would run in your environment and Prefect won’t have access to the code.
o
yeah but in that case i don't want to host a prefect cloud UI itself
i only host the worker + flow, and i want to watch it from app.prefect.cloud
a
You can do that with Prefect Cloud too! You just need to make sure you set your
PREFECT_API_URL
and
PREFECT_API_KEY
as environment variables on your Docker container.
1