【发布时间】:2021-03-02 22:03:33
【问题描述】:
我的 Django 项目 工作正常 与 python manage.py runserver 没有问题。 Postgres、redis、django、djangorestframework 都很好。
我尝试 Dockerize 项目,但 Postgres 出现以下错误:
....
web_1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
web_1 | django.db.utils.OperationalError: could not connect to server: Connection refused
web_1 | Is the server running on host "127.0.0.1" and accepting
web_1 | TCP/IP connections on port 5432?
这是我的 docker-compose。
version: '3'
services:
db:
image: postgres # use latest official postgres version
env_file:
- database.env # configure postgres
volumes:
- database-data:/var/lib/postgresql/data/ # persist data even if container shuts down
redis:
image: bitnami/redis:latest
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
volumes:
database-data:
注意:我还尝试了另一种 postgres 存储库: https://github.com/sameersbn/docker-postgresql
【问题讨论】:
标签: django postgresql docker