Mounting Volume to DockerRun for Local Storage

When using Local Storage (with the flow stored on the host machine) with DockerRun, the Flow needs to be accessible from inside the container. There are two ways to do this:

  1. Create a new image that contains the Flow file. The LocalStorage can then point to the location of the file inside the container. An example can be found here

  2. For faster prototyping, you can develop locally and just mount the local directory to the DockerRun Container. In order to do this, just mount the local directory on the agent.

prefect agent docker start --volume /Users/kevinkho/Work/scratch/:/usr/src/prefect

And then the Flow storage can point to the mount

from prefect import Flow, task
from import Local
from prefect.run_configs import DockerRun

def do_something(x: int):
    return x

with Flow(
    storage=Local(stored_as_script=True, path="/usr/src/prefect/"),
) as flow:
    do_something(1) = False

But this means that the agent has to add the volume to every flow run it deploys. To mount a volume for a specific flow, the Run Configuration can be used.

The file in this setup lives in:

with Flow(
    storage=Local(stored_as_script=True, path="/usr/src/prefect/"),
            "binds": {
                "/Users/kevinkho/Work/scratch/": {
                    "bind": "/usr/src/prefect/",
                    "mode": "rw",
) as flow:
1 Like

Can you do something like this with a cifs mount that has authentication credentials? Essentially a volume created with docker volume create

Joe, check this Low-level API — Docker SDK for Python 5.0.3 documentation

looks like the answer is Yes, if you leverage this arg instead of binds:

  • volumes_from (list) – List of container names or IDs to get volumes from.