我在使用Docker中运行PostGIS和Django时遇到了错误。我正在尝试设置Django项目来使用PostGIS数据库。
docker-compose.yml
->docker-compose.yml文件
version: '3'
services:
db:
image: postgis/postgis
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- 5432:5432
web:
build: .
command: bash -c "
python manage.py makemigrations
&& python manage.py migrate
&& python manage.py runserver 0.0.0.0:8000
"
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
错误信息:
web_1 | File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect
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 "db" (192.168.192.2) and accepting
web_1 | TCP/IP connections on port 5432?
web_1 |
ht_djangoapp_web_1 exited with code 1
docker-compose up -d
,等待30-60秒然后再尝试一次会起作用吗? - David Maze