在azure上部署flask应用程序时遇到问题。这个应用程序是一个简单的flask应用程序,它使用celery 作为任务队列,redis作为消息代理。当我打电话时,这个应用程序在我的本地机器(windows10)上运行良好 docker-compose up --build
. 在将应用程序部署到azure时,我似乎不知道自己做错了什么。
该应用程序似乎部署正常,除非我尝试执行异步任务-它挂起并在浏览器中给出意外的错误响应。
这是我的docker-compose.yml文件:
version: '2'
services:
redis:
image: 'redis:3.0-alpine'
command: redis-server
volumes:
- 'redis:/var/lib/redis/data'
ports:
- '6379:6379'
website:
- celery
build: .
command: >
gunicorn -b 0.0.0.0:5000
--access-logfile -
--reload
"flask_app.app:create_app()"
environment:
PYTHONUNBUFFERED: 'true'
volumes:
- '.:/flask_app'
ports:
- '5000:5000'
celery:
restart: always
build: .
command: celery worker -l info -A flask_app.tasks
env_file:
- '.env'
volumes:
- '.:/flask_app'
volumes:
redis:
这是我的文件:
FROM python:3.7.5-slim-buster
ENV INSTALL_PATH /flask_app
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000 6379
CMD gunicorn -b 0.0.0.0:5000 --access-logfile - "flask_app.app:create_app()"
以下是错误日志的片段:
ERROR] Error handling request /longtask
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 559, in connect
sock = self._connect()
File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 585, in _connect
socket.SOCK_STREAM):
File "/usr/local/lib/python3.7/socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/celery/backends/redis.py", line 127, in reconnect_on_error
yield
File "/usr/local/lib/python3.7/site-packages/celery/backends/redis.py", line 177, in _consume_from
self._pubsub.subscribe(key)
File "/usr/local/lib/python3.7/site-packages/redis/client.py", line 3580, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "/usr/local/lib/python3.7/site-packages/redis/client.py", line 3468, in execute_command
self.shard_hint
File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 1192, in get_connection
connection.connect()
File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 563, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error -2 connecting to redis:6379. Name or service not known.
我尝试过:
包括 .gitattributes
文件,以确保shell脚本使用lf作为行尾。
在docker compose文件中包含一个网络,如本文所建议的:错误:无法连接到redisredis:6379:名称或服务未知
在docker compose文件中添加'depends\u on:-celery-redis',如stackoverflow的其他地方所建议的那样。如何使用docker compose将多个平均应用容器部署到azure
看起来应用程序无法发现redis服务,或者没有在azure上正确启动(使用docker compose preview)。我是新的网络开发,azure和堆栈溢出。我不太确定如何在azure上解决此问题,并将感谢任何帮助。
谢谢。
暂无答案!
目前还没有任何答案,快来回答吧!