hi, I’m having some trouble setting up the Docker ...
# ask-community
t
hi, I’m having some trouble setting up the Docker container correctly for Flow to register. Could someone take a look? The Dockerfile setup correctly and working on local testing (with flow.run()); • I’m using Docker Storage like this, which the dockerfile is working correctly to call my modules:
Copy code
storage = Docker(
    dockerfile="./Dockerfile"
)
But the register always report the module not exists.
Copy code
ModuleNotFoundError: No module named 'criteo'
I’ve also packaged my modules in Dockerfile
k
Hey @Tony Yun, registration needs
criteo
to be installed as it runs your Python code. Do you have it installed on registration side?
t
yes, I can import both locally and in the container: for example in the container:
Copy code
$ docker run -it test_criteo /bin/bash                                               
root@ec16afad30d8:/app# python -c "import criteo"
the test_criteo is the image I built using the same Dockerfile
k
what does
pip show criteo
give you?
t
Copy code
root@5d226792ed82:/app# pip show criteo
WARNING: Package(s) not found: criteo
hmm 🤔
I didn’t push the package to pypi index. it’s just installed locally using poetry:
Copy code
[tool.poetry]
packages = [
    { include = "utils" },
    { include = "criteo" },
]

poetry install
k
This is my output for a custom package
Copy code
pip show mypackage
Name: mypackage
Version: 0.1
Summary: UNKNOWN
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: UNKNOWN
Location: /Users/kevinkho/Work/demos/blogs/prefect-docker/docker_with_local_storage
Requires: prefect
Required-by:
So it should still give you the location. What happens when you type
python
and then
import criteo
in the terminal?
t
that does work.. which i don’t know how though
is your
mypackage
built using this repo that you shared earlier? https://github.com/kvnkho/demos/tree/main/blogs/prefect-docker/docker_with_local_storage
k
Yes!
t
oh okay.. let me revisit. I was using poetry to install local packages
k
Can you try typing
which prefect
and show me the output?
t
Copy code
/usr/local/bin/prefect
k
Btw just so you know, there is a workaround where you can import criteo inside a task or function to defer the import.
t
oh what is it?
k
You just move the import inside a task instead of the top of the script.
t
yeah truely worked.. hmm. I will still try to avoid making such workarounds otherwise new folks have no idea to understand why have to do so. Nevermind, let me rethink about it for now.
k
Yeah for sure. Maybe you can try making an environment from scratch and trying again? It just feels like something off with the environments. I am not so familiar with poetry but I believe it uses pip under the hood so now sure why that would happen.
t
that it is not possible to use poetry to do so
k
that’s good to know! thanks for mentioning. pretty surprising
t
yeah.. thanks for your help too!
hey @Kevin Kho, I followed exactly as your example now but see this error when registered to Cloud:
Copy code
(flow built with '3.8.2', currently running with '3.7.11')
My dockerfile is:
Copy code
FROM prefecthq/prefect:0.15.4-python3.7

WORKDIR /app

COPY . .

RUN pip install -e .
My python version is also 3.7.11. Don’t where the 3.8.2 comes from.
k
What this says is the environment that registered the flow is on python 3.8.2 😵. Wondering if it’s some poetry stuff again?
t
no, no poetry stuff anymore.. only setup.py and requirements.txt now
I ran python on both local and Docker container, it’s 3.7.11
oh one sec
yeah it still failed for this reason. I thought I registered the wrong flow but not.
k
How are you registering your flows?
flow.register()
or prefect CLI?
t
using CLI. I think i just figured. the register failed because of
registry_url
added in DockerStorage. I thought I don’t need it to succeed since I’m using local Agent.
now I registered successfully and the error is gone. But new issue comes.. the flow is kept behind schedule. I have started my agent running..
k
Ah ok yeah that uploads the image there if provided.
t
k
Ah that’s because you used a Local Agent but used DockerRun right? I think you need a Docker agent?
t
yeah
oh okay
I’ll use a Kube agent then
k
No….Docker agent
t
oh okay
k
prefect agent docker start
😆. DockerRun pairs with Docker agent. Are you using KubernetesRun? That would pair with the Kubernetes agent
t
oh yeah it works now!!
I’m using DockerStorage, with no Runconfig specified
I thought I can use KubeRun with DockerStorage locally
k
Oh if no RunConfig is specified, I think any agent should be able to pick it up. The default is UniversalRun, but really I think it’s better to be explicit. KubeRun and DockerStorage will work I think, you just need the Kubernetes Agent
t
ok I’ll try it out. At least it works as nice as locally now! so happy. Thank you for the help!!
k
Of course.
t
hi Kevin, do you have a kubeRun flow file for example? I configured my own kube cluster and kube agent run, with also KubeRun config. but it doesn’t work:
Copy code
Event: 'Failed' on pod 'prefect-job-bfd2714e-vqgcj'
	Message: Failed to pull image "criteo-report:2021-09-01t20-22-23-258252-00-00": rpc error: code = Unknown desc = Error response from daemon: pull access denied for criteo-report, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
My agent:
Copy code
prefect agent kubernetes install | kubectl apply --namespace=default -f -
prefect agent kubernetes start

[2021-09-01 20:21:53,363] INFO - agent | Waiting for flow runs...
[2021-09-01 20:24:52,971] INFO - agent | Deploying flow run 57edb152-75f6-4b23-8c56-3cf4af2133d5 to execution environment...
[2021-09-01 20:24:53,184] INFO - agent | Completed deployment of flow run 57edb152-75f6-4b23-8c56-3cf4af2133d5
My flow:
Copy code
with Flow(
    name="Criteo Report",
    storage=storage,
    run_config=KubernetesRun(image="criteo-report:latest"),
    executor=LocalExecutor()
it seems I miss something in the documentation: https://docs.prefect.io/orchestration/agents/kubernetes.html#running-in-cluster the kubernetes is looking for a
repository
which I don’t know how to push the container to
k
I see. Looks like Kubernetes pulls it from DockerHub by default. I think you’re gonna need to upload the image to a place to get it to work with Kubernetes
t
oh okay. so cannot work with local images
k
Is your Kubernetes backed by a cloud? Azure K8S? Google K8S?
t
I’m not trying to use the cloud kubernetes yet. Just testing locally using minikube
k
Ah ok I think you need to do this . Looks like K8s has it’s own separate image registry.
t
nice thanks! let me try it out