Hey, dear community, I have a quick question on the capabilities to run docker tasks as sidecars on ...
x
Hey, dear community, I have a quick question on the capabilities to run docker tasks as sidecars on k8s(see the official example here https://docs.prefect.io/orchestration/recipes/k8s_docker_sidecar.html) . For our use case scenario, we are going to have two docker images being pulled and executed one by another. Should we define two flow container entries in the job template (flow-container1, flow-container2)? or just keep it as what it is from the example code? Much appreciated!
k
Hey @Xinchi He, do you mean docker_image1 executes docker_image2, or you really mean execute one another?
x
Hey @Kevin Kho! I meant docker_image1 as task1 and docker_image2 as task2, task1 --> task2. Task1 and task2 are independent, but we'd love it to be executed in 1 --> 2 order.
k
Ah ok my understanding is the job template will not changed. You just need to repeat this section for each container. Just add more tasks to start those containers
Copy code
with Flow("Docker sidecar example") as flow:
    # Create and start the docker container
    container_id = create_container(image)
    started = start_container(container_id=container_id)
    # Once the docker container has started, wait until it's completed and get the status
    status_code = wait_on_container(container_id=container_id, upstream_tasks=[started])
    # Once the status code has been retrieved, retrieve the logs
    logs = get_logs(container_id=container_id, upstream_tasks=[status_code])
and then you just need to know the syntax to chain upstream dependencies
Copy code
with Flow(...) as flow:
    a = task1()
    b = task2(x, upstream_tasks=[a])
x
@Kevin Kho I see. that
flow-container
stuff is a placeholder, and each time a
dockerPull
will overwrite that placeholder if I understand it correctly. We'll give it a shot, thanks!!
k
no no. you are running two containers because the first is the process for the flow code, and the second is the docker in docker server. i think your
flow_container1
and
flow_container2
will be separate containers from the original flow container
x
So it will be ["flow_container", "docker in docker server", "my_container1", "my_container2"] as sidecars in the end?
k
I don’t think sidecar is the right term but i think yes you will have those containers
x
Thanks! We'll give it try!