简体   繁体   English

Docker-compose - 模块导入问题

[英]Docker-compose - module import issue

I am working on a Flask app and my docker-compose.yml is not able to find my config folder.我正在开发 Flask 应用程序,而我的docker-compose.yml无法找到我的配置文件夹。 I have __init__.py files at every levels and I tried to add/remove the config path from my docker-compose.yml file but still the same issue.我在每个级别都有__init__.py文件,我尝试从docker-compose.yml文件中添加/删除配置路径,但仍然是同样的问题。 This is my project structure:这是我的项目结构:

.
├── ...
├── web_messaging                    
│   ├── app.py 
│   ├── __init__.py        
│   ├── ...       
│   └── config 
│       ├── settings.py 
│       ├── gunicorn.py
│       └── __init__.py
│            
├── __init__py             
├── .env             
├── requirements.txt              
├── docker-compose.yml
└── Dockerfile

When I am running docker-compose up --build , I am getting this error:当我运行docker-compose up --build时,我收到此错误:

website_1  | - 'config' not found.
website_1  | 
website_1  | Original exception:
website_1  | 
website_1  | ModuleNotFoundError: No module named 'config'
website_1  | [2021-04-04 15:23:26 +0000] [8] [INFO] Worker exiting (pid: 8)
website_1  | [2021-04-04 15:23:26 +0000] [1] [INFO] Shutting down: Master
website_1  | [2021-04-04 15:23:26 +0000] [1] [INFO] Reason: Worker failed to boot.

docker-compose.yml docker-compose.yml

version: '2'

services:
  website:
    build: .
    command: >
      gunicorn -c "python:web_messaging.config.gunicorn" --reload "web_messaging.app:create_app()"
    env_file:
      - '.env'
    volumes:
      - '.:/web_messaging'
    ports:
      - '8000:8000'

app.py应用程序.py

def create_app(settings_override=None):
    """
    Create a Flask application using the app factory pattern.

    :param settings_override: Override settings
    :return: Flask app
    """
    app = Flask(__name__, instance_relative_config=True)

    app.config.from_object('config.settings')
    app.config.from_pyfile('settings.py', silent=True)

    if settings_override:
        app.config.update(settings_override)

    error_templates(app)
    app.register_blueprint(user)
    app.register_blueprint(texting)
    extensions(app)
    configure_context_processors(app)
    return app
...

Dockerfile Dockerfile

FROM python:3.7.5-slim-buster

RUN apt-get update && apt-get install -qq -y \
  build-essential libpq-dev --no-install-recommends

ENV INSTALL_PATH /web_messaging
RUN mkdir -p $INSTALL_PATH

WORKDIR $INSTALL_PATH

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

COPY . .

CMD gunicorn -c "python:web_messaging.config.gunicorn" "web_messaging.app:create_app()"

Seems I solved it.看来我解决了。 The config folder must be outside of the main_messaging folder, config文件夹必须在main_messaging文件夹之外,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM