我正在尝试为任务队列运行Redis服务器。它可以在我的本地笔记本电脑上工作,但是当我将其移植到虚拟机(CentOS)时,会出现此错误:
redis.exceptions.ConnectionError: Error -3 connecting to redis:6379. Temporary failure in name resolution.
我查了一下,没有线程出现此特定错误。好像没有人遇到过吗?我的代码段如下:
redis_url = current_app.config['REDIS_URL']
with Connection(redis.from_url(redis_url)):
q = Queue()
task = q.enqueue(upload_data_to_ES, args=(data,), job_timeout=150, result_ttl=1000)
唯一的主要区别是我将docker-compose.yml
文件设置为具有network_mode: "host"
,以便它可以与虚拟机上的弹性搜索服务器通信。这会引起问题吗?我不知道它们之间的关系。帮助将不胜感激。
我的docker-compose.yml
文件如下:
version: '3.7'
services:
gilsonapp:
build: .
network_mode: "host"
image: gilsonapp:latest
container_name: gilsonapp
ports:
- 8003:8003
command: python app.py
volumes:
- ./app:/usr/src/app
- /test_files:/usr/src/app/mnt/tsl_files
environment:
- FLASK_DEBUG=1
- FLASK_ENV=testing
- REDIS_URL="redis://redis:6379/0"
env_file:
- oracle_env_vars
working_dir: /usr/src/app
depends_on:
- redis
worker:
image: gilsonapp
container_name: gilsonapp_worker
command: python worker.py
volumes:
- ./app:/usr/src/app
working_dir: /usr/src/app
environment:
- REDIS_URL="redis://redis:6379/0"
- APP_SETTINGS=config.TestingConfig
depends_on:
- redis
redis:
image: redis:alpine
expose:
- '6379'