Suppose I have a flow. In the flow, I want to run ...
# ask-community
d
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
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
will it also accept
mount
?
thank you!
👍 1
s
@Nate I’m following your guide above, but when I run the DockerContainer as per below it fails with : 404 Client Error for http+docker://localhost/v1.41/images/create?tag=latest&fromImage=merge: Not Found (“pull access denied for merge, repository does not exist or may require ‘docker login’: denied: requested access to the resource is denied”) from prefect.infrastructure.container import DockerContainer DockerContainer( image=“merge”, command=[“python”, “/app/modules/merge/scripts/run_test_script.py”] ).run() But I can get the corresponding docker bash line to run docker run --entrypoint python merge /app/modules/merge/scripts/run_test_script.py So how do I setup the DockerContainer to ‘connect’ to my local docker? Are there permissions I need to set? I’ve not installed a Block in the server as that looks like it relates to remote docker instances. Any ideas?