1

I'm new to docker and prefect and trying to run a basic prefect flows with docker container from my local windows.

Here is my Docker file

# We're using the latest version of Prefect with Python 3.10
FROM prefecthq/prefect:2-python3.10

RUN apt-get update && apt-get install -y curl

# Add our requirements.txt file to the image and install dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt --trusted-host pypi.python.org --no-cache-dir

# Add our flow code to the image
COPY . /opt/prefect/flows
WORKDIR /opt/prefect/flows

ENV PREFECT_API_URL="http://127.0.0.1:4200/api"
ENV PREFECT_API_DATABASE_CONNECTION_URL="postgresql+asyncpg://prefect:[email protected]/prefect"

CMD python etl_flows.py && prefect server start

And below is how I build and run this docker file by CMD

docker build -t my-prefect-flow .

docker run -d --name postgres -e POSTGRES_USER=prefect -e POSTGRES_PASSWORD=prefect -e POSTGRES_DB=prefect -p 5432:5432 postgres:13

docker run -p 4200:4200 --name prefect-server --link postgres my-prefect-flow

When I run in logs I could see below

___ ___ ___ ___ ___ ___ _____
| _ \ _ \ __| __| __/ __|_  _|
| _/  / _|| _|| _| (__ | |
|_| |_|_\___|_| |___\___| |_|

Configure Prefect to communicate with the server with:

  prefect config set PREFECT_API_URL=http://127.0.0.1:4200/api

View the API reference documentation at http://127.0.0.1:4200/docs

Check out the dashboard at http://127.0.0.1:4200

But when I go to http://127.0.0.1:4200 It is giving me error as This page isn’t working 127.0.0.1 didn’t send any data.ERR_EMPTY_RESPONSE

Here is my etl_basic flow

import prefect
from prefect import task, flow
from prefect import get_run_logger

@task
def say_hi():
    logger = get_run_logger()
    logger.info("Hello from the Health Check Flow! 👋")


@task
def log_platform_info():
    import platform
    import sys
    from prefect.server.api.server import SERVER_API_VERSION

    logger = get_run_logger()
    logger.info("Host's network name = %s", platform.node())
    logger.info("Python version = %s", platform.python_version())
    logger.info("Platform information (instance type) = %s ", platform.platform())
    logger.info("OS/Arch = %s/%s", sys.platform, platform.machine())
    logger.info("Prefect Version = %s 🚀", prefect.__version__)
    logger.info("Prefect API Version = %s", SERVER_API_VERSION)


@flow(name="Health Check Flow")
def health_check_flow():
    hi = say_hi()
    log_platform_info(wait_for=[hi])

I tried to expose a different port and also with container port but the result is same. If I try to run prefect server start directly in my local, the IP is working and UI is routing correctly it's only problem with docker

2
  • I'm not familiar with Prefect, but would it not make sense to run prefect server start first, and then your Python script, which presumably needs it to be running?
    – tripleee
    Commented Jul 5 at 5:59
  • Do you need to set PREFECT_SERVER_API_HOST=0.0.0.0, as in this answer? This seems like the symptom where a process is only listening on the container-private localhost interface and is unreachable from outside its own container.
    – David Maze
    Commented Jul 5 at 10:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.