Tom Tom
08/25/2021, 11:46 PMDockerRun(image="prefecthq/prefect")
with prefect agent docker start
i´m getting this Error:
Failed to load and execute Flow's environment: ModuleNotFoundError("No module named 'C'")
I know that i can´t import other dependencies but i only import following modules from prefect in the script:
from prefect import Flow, task
from prefect.run_configs import LocalRun,DockerRun
Or is it possible to run DockerRun()
in an existing Container?nicholas
Tom Tom
08/26/2021, 12:11 AM"prefecthq/prefect"
.
I´ll build a custom image on base on "prefecthq/prefect"
with the prefect dependencies, hope it works 🙂nicholas
nicholas
Tom Tom
08/26/2021, 12:23 AMfrom prefect import Flow, task
from prefect.run_configs import LocalRun,DockerRun
#classes
class eins:
@task
def function():
return 1
Test=eins()
#Flow
with Flow("Prefect Test Flow") as flow:
a = Test.function()
#flow.run_config = LocalRun()
flow.run_config = DockerRun(image="new")
flow.register(project_name="test")
I start my server on CMD with prefect server start
and my docker agent also on CMD with prefect agent docker start --label Andromeda
. Andromeda is my PC-Name, if I don´t define it, the agent will not run anything and the tasks will be "late" but not executing.Kevin Kho
~/.prefect
by default when you register. I think you are on a Windows machine so your home evaluates to C:/users/something
. And then when you use DockerRun
it imports your flow from LocalStorage
and looks for it under the ~.prefect
folder. But you don’t have C:/users/something
.Kevin Kho
Kevin Kho
Flow("docker_example", storage=Local(path="/app/workflow/flow.py",stored_as_script=True)
will mean that you copied the Flow with filename flow.py
to /app/workflow/
Kevin Kho
Tom Tom
08/26/2021, 1:41 AMTom Tom
08/26/2021, 7:27 PMFailed to load and execute Flow's environment: ModuleNotFoundError("No module named"test.py"
.
I use Docker Desktop on Windows and so my Docker Container should be stored in C:\Users\Tom\AppData\Local\Docker\wsl\data
. I used different paths like:
/test.py
/Desktop/test.py
../../../../../Desktop/test.py
/var/lib/docker/test.py
I run my agent and server from C:\Users\Tom
Kevin Kho
Tom Tom
08/26/2021, 7:41 PMrun_config=DockerRun(image="prefecthq/prefect")
, so i use the prefect standard docker image and i dont have any Dockerfile(i think?).
with Flow("Prefect_Test_Flow",storage=Local(path="/Desktop/test.py",stored_as_script=True), run_config=DockerRun(image="prefecthq/prefect")) as flow:
a = Test.function()
Kevin Kho
Local(path="Desktop/test.py")
will look for that path inside the container so you need to get the file inside the container somehow.Tom Tom
08/26/2021, 7:49 PMrun_config=DockerRun(image="prefecthq/prefect")
a container? because at the moment no container is running.Kevin Kho
prefecthq/prefect
and then look for the local path (relative to the container), and then load the flow and run it on top. This path thing is trickier with Local
but with something like GitHub
or S3
you don’t need to worry about that script being stored in the image since it will be downloaded during runtime. Local
just needs it to be in the local directory. If you are using DockerRun
, it’s a path in the container. If you are using LocalRun
, it’s a path on the host machine.Tom Tom
08/26/2021, 8:07 PMdocker cp <src-path> <container>:<dest-path>
i need to copy the file into the container, so the agent find/load and can run the flows. But this is tricky cause during runtime ofc i cant use comands, maybe i can start a container manually, copy file, and then run the flow with DockerRun()
and pass them the container ID?Kevin Kho
dockerpy's
create_container
so I don’t believe you can just pass a container to DockerRun. DockerRun also does not take a container id as an argument.Tom Tom
08/26/2021, 8:14 PMTom Tom
08/26/2021, 8:49 PM[26 August 2021 10:48pm]: All reference tasks succeeded.
You guys are awesome, thank you very much for your help 🎉 @Kevin Kho @nicholas
To other ppl with the same problem, Dockerfile looks like:
FROM prefecthq/prefect:latest
WORKDIR /app
COPY test.py /app/test.py
And the flow/DockerRun is the same as above, with new image ID and path="/app/test.py"
👍Kevin Kho
Tom Tom
08/26/2021, 9:01 PMDockerRun()
more than one path/file? Or 1 flow 1 file?Kevin Kho
Storage
concept rather than the RunConfiguration
, but yes you can include multiple files in the container. Check this for more information on Docker storage. If those are files you need to import, it’s best to install as a Python module. If those are files you read in like .sql
or .yaml
then just including them in the container for your Flow to use will work.Tom Tom
08/26/2021, 9:22 PM