[英]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.