Dear Prefect community, I need some help as we are trying out prefect as our tool for workflow orch...
d
Dear Prefect community, I need some help as we are trying out prefect as our tool for workflow orchestration tool. I am wanting to create a simple workflow that basically pulls an image from a private docker repository and that it runs it on the agent (which has access to the hosts docker socket). This docker image when running will perform some tasks. Is there a guide I can use to create this minimalistic setup? Or could someone help me figure this one out?
#C048ZHNT9QS any help would be greatly appreciated
n
hi @Dijar Vrella here's a guide for getting started • define your flow
Copy code
from prefect import flow


@flow(log_prints=True)
def hello_docker():
    """
    A simple flow that prints 'Hello, Docker!' to the logs
    """
    print("Hello, Docker!")


if __name__ == "__main__":
    hello_docker()
• define your deployment ◦ using `prefect.yaml` (my preference) ◦ using `.deploy` • start a worker
prefect worker start --type docker --pool my-pool
d
Hi Nate, thank you for your reply. I will have a look at this and come back with questions if I have. So in this hello_docker function I would have to specify i.e. run this thing or something right?
👍 1
n
the
hello_docker
function in my example represents your flow that a worker would submit for execution as a container so if you went the
prefect.yaml
route, you would • create your deployment with
prefect deploy -n hello-docker
given the 2 files I referenced • start a worker `prefect worker start --type docker --pool your-pool`(which creates
your-pool
if it doesnt already exist) • either run
prefect deployment run ...
or click run on your deployment in the UI to have it execute ie the worker is responsible for picking up the function at your
entrypoint
and submitting it according to the infra config (i.e work pool)
does that answer your question?
d
oh so I see this flow only runs the new container that get build then docker image can have its own entrypoint that does whatever it does but from prefect perspective we just using this to trigger that part right?
cool if what I explained is what you also tried to explain than looks promising
also can you have me understand how I can make sure that when I run my container the following parameters:
docker run --gpus all -v "$(pwd)/../test.py:/workspace/test.py" -v /ninjadata:/ninjadata --group-add ninja -it --cap-add SYSLOG  ninja/build:$1 python test.py
how can achieve that with prefect.yaml: pulling an image on this repo:
ninja/build:latest
running the container that passes these parameters:
docker run --gpus all -v "$(pwd)/../test.py:/workspace/test.py" -v /ninjadata:/ninjadata --group-add ninja -it --cap-add SYSLOG  ninja/build:latest
Also pass the
python test.py
to be executed
sorry if all of this doesn't make any sense but I can hop on a call and try to explain some stuff maybe easier?
n
hi @Dijar Vrella - you can always use the
docker
client directly from within a flow like
hello_docker
that could use any docker features that the work pool may not support for example the
gpus
flag is not currently supported directly in the docker work pool (though we'd like to add it) so you could just write / deploy a flow that invokes docker however you need you can schedule a call here