简体   繁体   English

运行 docker 时无法将“app.server”解析为属性名称或 function 调用

[英]Failed to parse 'app.server' as an attribute name or function call when running docker

I am trying to run my app from docker and I am getting this error message from docker logs for my dash.我正在尝试从 docker 运行我的应用程序,并且我从我的仪表板的docker logs中收到此错误消息。 I have searched a lot but could not find anything.我搜索了很多,但找不到任何东西。 Please help!请帮忙!

The log message from docker logs for dash image来自docker logs的日志消息记录了破折号图像

[2020-08-22 06:44:32 +0000] [1] [INFO] Starting gunicorn 20.0.4
[2020-08-22 06:44:32 +0000] [1] [INFO] Listening at: http://0.0.0.0:8050 (1)
[2020-08-22 06:44:32 +0000] [1] [INFO] Using worker: sync
[2020-08-22 06:44:32 +0000] [8] [INFO] Booting worker with pid: 8
Failed to parse 'app.server' as an attribute name or function call.
[2020-08-22 06:44:33 +0000] [8] [INFO] Worker exiting (pid: 8)
[2020-08-22 06:44:33 +0000] [1] [INFO] Shutting down: Master
[2020-08-22 06:44:33 +0000] [1] [INFO] Reason: App failed to load.

My API is working fine我的 API 工作正常

[2020-08-22 06:44:31 +0000] [1] [INFO] Starting gunicorn 20.0.4
[2020-08-22 06:44:31 +0000] [1] [INFO] Listening at: http://0.0.0.0:5000 (1)
[2020-08-22 06:44:31 +0000] [1] [INFO] Using worker: sync
[2020-08-22 06:44:31 +0000] [8] [INFO] Booting worker with pid: 8

This is my Dash app.这是我的 Dash 应用程序。 File name is app.py inside dash folder.文件名是dash文件夹中的app.py

app = dash.Dash(
    __name__,
    external_stylesheets=external_stylesheets,
    meta_tags=[
        {"name": "viewport", "content": "width=device-width, initial-scale=1"}
    ],
    suppress_callback_exceptions=True
)

if __name__ == '__main__':
    ENVIRONMENT = os.environ.get("ENVIRONMENT", "dev")
    DEBUG = ENVRIONMENT == "dev"
    HOST = '0.0.0.0' if ENVIRONMENT == "prod" else 'localhost'
    app.run_server(debug=DEBUG, host=HOST)

This is my Dockerfile for Dash这是我的Dockerfile用于 Dash

FROM python:3.7

ADD requirements.txt /app/
WORKDIR /app
RUN pip install -r requirements.txt

ADD . /app

EXPOSE 8050

CMD ["gunicorn", "-b", "0.0.0.0:8050", "app:app.server"]

and this is my docker-compose.yml file这是我的docker-compose.yml文件

version: '3'
services:
  api:
    build:
      context: src/api
      dockerfile: Dockerfile
    environment:
      - ENVIRONMENT=prod
    restart: always
  dash:
    build:
      context: src/dash
      dockerfile: Dockerfile
    ports:
      - "8050:8050"
    environment:
      - ENVIRONMENT=prod
      - API_URL=http://api:5000/api
    depends_on:
      - api
    restart: always

This is my api code as app.py file in api folder这是我的 api 代码作为app.py文件夹中的api文件

app = Flask(__name__)
api = Blueprint('api', __name__)

app.register_blueprint(api, url_prefix='/api')

if __name__ == "__main__":
    ENVIRONMENT = os.environ.get("ENVIRONMENT", "dev")
    DEBUG = ENVIRONMENT == "dev"
    HOST = '0.0.0.0' if ENVIRONMENT == "prod" else 'localhost'
    app.run(debug=DEBUG, host=HOST)

This is my Dockerfile for api这是我的Dockerfile用于 api

FROM python:3.7

ADD requirements.txt /app/
WORKDIR /app

RUN pip install -r requirements.txt

ADD . /app

EXPOSE 5000

CMD ["gunicorn", "-b", "0.0.0.0:5000", "app:app"]

This is what i get after running docker-compose up --build -d这是我在运行docker-compose up --build -d后得到的

Step 5/7 : ADD . /app
 ---> 5f1b89f2daeb
Step 6/7 : EXPOSE 5000
 ---> Running in 74a03831d03e
Removing intermediate container 74a03831d03e
 ---> cab01af5bfee
Step 7/7 : CMD ["gunicorn", "-b", "0.0.0.0:5000", "app:app"]
 ---> Running in 606197aae6fd
Removing intermediate container 606197aae6fd
 ---> 35be6754e766
Successfully built 35be6754e766
Successfully tagged appname_api:latest
Building dash
.
.
.

Step 5/7 : ADD . /app
 ---> c1111dca7a60
Step 6/7 : EXPOSE 8050
 ---> Running in ef1a216db216
Removing intermediate container ef1a216db216
 ---> a84d1d8ce503
Step 7/7 : CMD ["gunicorn", "-b", "0.0.0.0:8050", "app:app.server"]
 ---> Running in afc121660ddc
Removing intermediate container afc121660ddc
 ---> 600011a005ca
Successfully built 600011a005ca
Successfully tagged appname_dash:latest
Creating appname_api_1 ... done
Creating appname_dash_1 ... done

I fixed this error on a coworker's app where they had the following in app.py :我在同事的应用程序上修复了这个错误,他们在app.py中有以下内容:

server = Flask(__name__) # define flask app.server
app = dash.Dash(
    __name__,
    server=server,
)

And then in an index.py they were doing:然后在index.py中他们正在做:

from app import app

server = app.server # I add this part here

And then the Docker CMD was:然后 Docker CMD 是:

CMD ["gunicorn", "index:server", "-b", ":8050"]

And it worked.它奏效了。

I had a slightly different error but google led me here so I am posting for others in a similar situation.我有一个稍微不同的错误,但谷歌把我带到了这里,所以我为其他处于类似情况的人发帖。 I had the below error:我有以下错误:

Failed to parse '' as an attribute name or function call.无法将 '' 解析为属性名称或 function 调用。

My problem was that in my Procfile I had a space between "wsgi:" and "app".我的问题是,在我的 Procfile 中,“wsgi:”和“app”之间有一个空格。 The below was the correct syntax for the Procfile.以下是 Procfile 的正确语法。

web: gunicorn wsgi:app web: gunicorn wsgi:app

The issue is with the arguments you're passing to gunicorn.问题在于您传递给 gunicorn 的 arguments。 Based on what you're showing here, I suggest you try changing:根据您在此处显示的内容,我建议您尝试更改:

CMD ["gunicorn", "-b", "0.0.0.0:8050", "app:app.server"] to: CMD ["gunicorn", "-b", "0.0.0.0:8050", "app:app.server"]到:

CMD ["gunicorn", "-b", "0.0.0.0:8050", "app:server"]

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

相关问题 Gunicorn 20 在 'index' 中找不到应用程序 object 'app.server' - Gunicorn 20 failed to find application object 'app.server' in 'index' FLASK:plotly:错误:模块“索引”没有属性“app.server” - FLASK : plotly : Error: module 'index' has no attribute 'app.server' 在 DJANGO 中运行服务器时应用程序名称未注册 - App name not registering when running server in DJANGO 在Docker中运行应用程序时出现ModuleNotFound - ModuleNotFound when running an app in Docker 使用函数变量调用类实例时,Python的“ str”对象没有属性“名称” - Python 'str' object has no attribute 'name' when using a function variable to call a class instance Gunicorn:尝试启动 flask 服务器时无法在 'wsgi' 中找到属性 'app' - Gunicorn: Failed to find attribute 'app' in 'wsgi' when attempting to start flask server 在 docker 容器上运行时,Flask 应用程序无法正常工作 - Flask App not working when running on docker container 运行 Dash 应用程序时名称或服务未知 - Name or service not known when running a Dash app Flask 在使用 docker 运行时在 OptionParser.parse_args() 处停止 - Flask stops at OptionParser.parse_args() when running it using docker 运行 flask 应用程序时出错 - 调用 python 脚本时未定义 function - Error when running flask app - function not defined when I make a call to the python script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM