Amine Dirhoussi
10/14/2021, 2:28 PMAndreas Tsangarides
10/14/2021, 2:33 PMAndreas Tsangarides
10/14/2021, 2:33 PMAnna Geller
Andreas Tsangarides
10/14/2021, 2:36 PMAmine Dirhoussi
10/14/2021, 2:57 PMAmine Dirhoussi
10/14/2021, 3:45 PMAmine Dirhoussi
10/14/2021, 3:54 PMimport prefect
from prefect import task, Flow, context
from prefect.run_configs import DockerRun
from prefect.storage import Local
@task
def hello_task():
logger = prefect.context.get("logger")
<http://logger.info|logger.info>("Hello task")
with Flow(
"docker_example",
# storage=Local(path="/app/test.py", stored_as_script=True),
run_config=DockerRun(image="test:latest", labels=["docker"]),
) as flow:
hello_task()
if __name__ == "__main__":
flow.register("docker_test")
I also build a docker image tagged test:latest :
FROM prefecthq/prefect:latest
WORKDIR /app
COPY . .
Kevin Kho
DockerRun
. It looks like it got your flow. What do you see when you say it gets stuck? Any logs?Andreas Tsangarides
10/14/2021, 5:31 PM# in the agent
show_flow_logs=True
also maybe try using prefect to build the image ?
storage = Docker(
registry_url=registry_url, # set to none for keeping image locally
image_name=image_name,
image_tag=image_tag,
dockerfile='Dockerfile', # path to your dockerfile
)
storage.build(push=push) # set false for not pushing the image to a registry and keep only local
Amine Dirhoussi
10/15/2021, 8:22 AM│[2021-10-15 08:17:30,735] INFO - agent | Deploying flow run 84bb1c3f-90dc-4633-b83f-f4c057cd1
│938 to execution environment...
│[2021-10-15 08:17:31,128] INFO - agent | Completed deployment of flow run 84bb1c3f-90dc-4633-
│b83f-f4c057cd1938
│Traceback (most recent call last):
│ File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 170, in _new_conn
│ (self._dns_host, self.port), self.timeout, **extra_kw
│ File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 96, in creat
e_connection
│ raise err
│ File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 86, in creat
e_connection
sock.connect(sa)
│ConnectionRefusedError: [Errno 111] Connection refused
Kevin Kho
docker run hello-world
in the command line on the machine you have the Docker agent on?Amine Dirhoussi
10/15/2021, 9:01 AMAmine Dirhoussi
10/15/2021, 9:16 AMdocker.errors.APIError: 500 Server Error for <http+docker://localhost/v1.41/build?t=test%3Alatest%3A2021-10-15t09-15-43->
Andreas Tsangarides
10/15/2021, 9:19 AMAmine Dirhoussi
10/15/2021, 9:21 AMimport prefect
from prefect import task, Flow, context
from prefect.run_configs import DockerRun
from prefect.storage import Local
from prefect.storage.docker import Docker
@task
def hello_task():
logger = prefect.context.get("logger")
<http://logger.info|logger.info>("Hello task")
# Configure storage as docker file
docker_storage = Docker(
registry_url=None, dockerfile="Dockerfile", image_name="test:latest"
)
docker_storage.build()
with Flow(
"docker_example",
storage=docker_storage,
# storage=Local(path="/app/test.py", stored_as_script=True),
run_config=DockerRun(image="test:latest", labels=["docker"]),
) as flow:
hello_task()
if __name__ == "__main__":
flow.register("docker_test")
Andreas Tsangarides
10/15/2021, 9:25 AMAmine Dirhoussi
10/15/2021, 9:31 AMAnna Geller
"""
prefect agent docker start --label docker
"""
from prefect import task, Flow
from prefect.run_configs import DockerRun
from prefect.storage import Docker
@task(log_stdout=True)
def hello_world():
print("hello world")
with Flow(
"dockerrun-test-flow",
storage=Docker(),
run_config=DockerRun(image="prefecthq/prefect:latest", labels=["docker"]),
) as flow:
hello_world()
Does this flow execute successfully?Amine Dirhoussi
10/15/2021, 9:44 AMprefect start server --expose
, apparently it is a Ubuntu issue. I 'll try without to check if it works without . Thanks a lotAnna Geller
FROM prefecthq/prefect:0.15.6-python3.8
if you use Python 3.8 and Prefect 0.15.6 on the machine from which you deploy your flow to ensure that the serialized flow is using the same version.
LMK if there is any other issue.Amine Dirhoussi
10/15/2021, 10:11 AM--expose
flag and the basic flow does not work.
I am still having connection issue, when trying to build my image using the Docker storage
and a custom Dockerfile. 😕Anna Geller
prefect server start
, it spins up all components as docker containers, and if not set up properly, you may end up running docker in docker.Anna Geller
Amine Dirhoussi
10/16/2021, 9:28 AMAnna Geller
Amine Dirhoussi
10/16/2021, 9:50 AM