https://prefect.io logo
d

Daniel Lyons

09/11/2023, 10:14 PM
Suppose I have a flow. In the flow, I want to run a task which is delivered to me as a container. Is there an easy way to have a task simply be “run this container with these arguments”, analogous to
docker run --rm --mount type=bind,source=$SRC,target=$DEST -it thing:label arg1 arg2 …
? My gut feeling is that the
DockerContainer
block should support this but I’m getting a feeling it is for another purpose than this, since I don’t see how to pass the arguments or mess around with the mounts
n

Nate

09/11/2023, 11:00 PM
hi @Daniel Lyons - you should be able to use
DockerContainer
for this
Copy code
In [6]: from prefect.infrastructure.container import DockerContainer
   ...:
   ...: DockerContainer(
   ...:     image="alpine:latest",
   ...:     command=["echo", "Arguments received:", "arg1", "arg2"]
   ...: ).run()

17:57:38.209 | INFO    | prefect.infrastructure.docker-container - Pulling image 'alpine:latest'...

17:57:39.756 | INFO    | prefect.infrastructure.docker-container - Creating Docker container with auto-generated name...
17:57:39.789 | INFO    | prefect.infrastructure.docker-container - Docker container 'brave_kalam' has status 'created'
17:57:40.003 | INFO    | prefect.infrastructure.docker-container - Docker container 'brave_kalam' has status 'exited'
Arguments received: arg1 arg2
17:57:40.024 | INFO    | prefect.infrastructure.docker-container - Docker container 'brave_kalam' has status 'exited'
Out[6]: DockerContainerResult(identifier='<http+docker://localhost:81>ce6a30ed4d5c27a0c9852e2703ae907b6a40fca6de16015364fa652f1df815', status_code=0)
where
DockerContainer
should also accept `volumes`
d

Daniel Lyons

09/11/2023, 11:01 PM
will it also accept
mount
?
thank you!
👍 1