Im getting this error in my flask container while starts with docker-compose up:
web_1 | Traceback (most recent call last):
web_1 | File "/app/app.py", line 3, in <module>
web_1 | from presentation.controllers.notifications import notifications_router
web_1 | File "/app/presentation/controllers/notifications.py", line 4, in <module>
web_1 | from app.presentation.models.notifications_body import NotificationsBody
web_1 | File "/app/app.py", line 3, in <module>
web_1 | from presentation.controllers.notifications import notifications_router
web_1 | ImportError: cannot import name 'notifications_router' from partially initialized module 'presentation.controllers.notifications' (most likely due to a circular import) (/app/presentation/controllers/notifications.py)
if i run this outside docker-compose it works normally, but in docker-compose it gives an error, does anyone know how to fix it?
this is my docker-compose.yml
version: '3.9'
services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
- "5000:5000"
depends_on:
- mongodb
- rabbitmq
- nginx
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
mongodb:
image: mongo:latest
ports:
- "27017:27017"
environment:
- MONGO_INITDB_DATABASE=test
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=admin
- MONGO_URI="mongodb://admin:admin@mongodb:27017/"
volumes:
- mongodb_data:/data/db
mongo-express:
image: mongo-express:latest
ports:
- "8081:8081"
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=admin
- ME_CONFIG_MONGODB_ADMINPASSWORD=admin
- ME_CONFIG_MONGODB_SERVER=mongodb
- ME_CONFIG_MONGODB_ENABLE_ADMIN=true
- ME_CONFIG_BASICAUTH_USERNAME=admin
- ME_CONFIG_BASICAUTH_PASSWORD=admin
depends_on:
- mongodb
rabbitmq:
image: rabbitmq:3-management
container_name: rabbitmq
restart: always
environment:
- RABBITMQ_DEFAULT_USER=admin
- RABBITMQ_DEFAULT_PASS=admin
- RABBITMQ_DEFAULT_VHOST=/
ports:
- 15672:15672
volumes:
- rabbitmq_data:/var/lib/rabbitmq
volumes:
mongodb_data:
rabbitmq_data:
app.py
from app.infrastructure.server import entrypoint
app = entrypoint.start()
if __name__ == '__main__':
app.run(host='0.0.0.0')
entrypoint.py
from flask import Flask
from app.infrastructure.server import url_mapping
def start():
"""
Starts the application
Returns:
Flask: Flask application
"""
app = Flask(__name__)
app.url_map.strict_slashes = False
url_mapping.map_routes(app)
app.app_context().push()
return app
url_mapping.py
from flask import Flask
from app.presentation.controllers.notifications import notifications_router
from app.presentation.controllers.ping_ctr import ping_router
def map_routes(application: Flask) -> None:
"""
Map routes
Args:
application (Flask): Flask application
"""
application.register_blueprint(ping_router)
application.register_blueprint(notifications_router)
Can someone help with this? tks!

look at your
app.presentation.models.notifications_bodyfilelooks like over there is imported something from app.py
if it don't help then pls add Dockerfile to the description of your question