Skip to content

How to write/run a basic Hello World for docker-compose #20085

@Nolaan

Description

@Nolaan

Bug summary

Hello I'm trying to run the getting started flow 01_getting_started.py
but the script fails as it can't import prefect, which is very weird. I'm running the latest image and it seems the configuration has circular dependencies.

Error log from the prefect-server container :

root@9ff3acc17dae:~# python /opt/scripts/01_getting_started.py                                                                                                                                                                                 
Failed to initialize plugins: cannot import name 'flow' from partially initialized module 'prefect' (most likely due to a circular import) (/usr/local/lib/python3.12/site-packages/prefect/__init__.py)                                       
Traceback (most recent call last):                                                                                                                                                                                                             
  File "/opt/scripts/01_getting_started.py", line 1, in <module>                                                                                                                                                                               
    from prefect import flow, task                                                                                                                                                                                                             
  File "/usr/local/lib/python3.12/site-packages/prefect/__init__.py", line 181, in __getattr__                                                                                                                                                 
    module = importlib.import_module(mname, package=package)                                                                                                                                                                                   
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                   
  File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module                                    
    return _bootstrap._gcd_import(name[level:], package, level)                                                        
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                        
  File "/usr/local/lib/python3.12/site-packages/prefect/main.py", line 3, in <module>                                  
    from prefect.states import State
  File "/usr/local/lib/python3.12/site-packages/prefect/states.py", line 3, in <module>                                
    import asyncio                                         
  File "/usr/local/lib/python3.12/asyncio/__init__.py", line 8, in <module>                                            
    from .base_events import *
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 18, in <module>                                        
    import concurrent.futures
  File "/usr/local/lib/python3.12/concurrent/futures/__init__.py", line 8, in <module>                                 
    from concurrent.futures._base import (FIRST_COMPLETED,
  File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 7, in <module>                                    
    import logging                                         
  File "/opt/scripts/logging.py", line 1, in <module>
    from prefect import flow, task
ImportError: cannot import name 'flow' from 'prefect' (/usr/local/lib/python3.12/site-packages/prefect/__init__.py)    

Here's my docker-compose:

services:
  postgres:
    image: postgres:14
    container_name: pfxpsql
    environment:
      POSTGRES_USER: default
      POSTGRES_PASSWORD: default
      POSTGRES_DB: prefect
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U prefect"]
      interval: 5s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7
    container_name: pfxredis
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD-SHELL", "redis-cli ping"]
      interval: 5s
      timeout: 5s
      retries: 5

      prefect-server:
    image: &image_version prefecthq/prefect:3.6.8-python3.12-kubernetes
    container_name: pfxserver
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      PREFECT_API_DATABASE_CONNECTION_URL: postgresql+asyncpg://prefect:prefect@postgres:5432/prefect
      PREFECT_SERVER_API_HOST: 0.0.0.0
      PREFECT_MESSAGING_BROKER: prefect_redis.messaging
      PREFECT_MESSAGING_CACHE: prefect_redis.messaging
      PREFECT_REDIS_MESSAGING_HOST: redis
      PREFECT_REDIS_MESSAGING_PORT: 6379
      PREFECT_REDIS_MESSAGING_DB: 0
      PREFECT_UI_API_URL: https://[redacted]/api
      # PREFECT_UI_SERVE_BASE:
      PREFECT_UI_URL: https://[redacted]
    command: prefect server start --no-services
    ports:
      - "4200:4200"
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request as u; u.urlopen('http://localhost:4200/api/health', timeout=1)"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  prefect-services:
    image: *image_version
    container_name: pfxservices
    depends_on:
      prefect-server:
        condition: service_healthy
    environment:
      PREFECT_API_DATABASE_CONNECTION_URL: postgresql+asyncpg://prefect:prefect@postgres:5432/prefect
      PREFECT_MESSAGING_BROKER: prefect_redis.messaging
      PREFECT_MESSAGING_CACHE: prefect_redis.messaging
      PREFECT_REDIS_MESSAGING_HOST: redis
      PREFECT_REDIS_MESSAGING_PORT: 6379
      PREFECT_REDIS_MESSAGING_DB: 0
    command: prefect server services start

  prefect-worker:
    image: *image_version
    container_name: pfxworker
    depends_on:
      prefect-server:
        condition: service_healthy
    environment:
      PREFECT_API_URL: http://prefect-server:4200/api
    command: prefect worker start --pool local-pool
    restart: on-failure

volumes:
  postgres_data:
  redis_data:

Version info

root@9ff3acc17dae:/opt/prefect# prefect version
Version:              3.6.9
API version:          0.8.4
Python version:       3.12.12
Git commit:           d5a15f55
Built:                Wed, Dec 31, 2025 10:21 PM
OS/Arch:              linux/x86_64
Profile:              ephemeral
Server type:          ephemeral
Pydantic version:     2.12.5
Server:
  Database:           postgresql
  PostgreSQL version: 14.11 (Debian 14.11-1.pgdg120+2)
Integrations:
  prefect-redis:      0.2.8

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions