【发布时间】:2019-02-20 16:18:08
【问题描述】:
试图在 docker 中运行我的 django 服务器,但 postgres 端口已被使用?当我运行“docker-compose up”时,我收到此错误:
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
ERROR: Service 'web' failed to build: The command '/bin/sh -c python manage.py migrate' returned a non-zero code: 1
sudo 服务 postgresql 状态
返回:
9.6/main (port 5432): online
sudo lsof -nP | grep 听
返回:
postgres 15817 postgres 3u IPv4 1022328 0t0 TCP 127.0.0.1:5432
我尝试运行“sudo kill -9 15817”,但 docker-compose up 仍然收到相同的错误。
Docker-compose.yml
version: '3'
services:
db:
image: postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'stemletics',
'USER': 'stemleticsadmin',
'PASSWORD': 'changeme',
'HOST': '127.0.0.1', # set in docker-compose.yml
'PORT': 5432 # default postgres port
}
}
【问题讨论】:
-
请发布您的 docker-compose 文件。您可能需要在 docker-compose 文件中将
network_mode: "host"添加到 django 服务。 -
我添加了我的 docker-compose.yml 文件
-
您的目标是在 Docker 中运行 postgres 吗?还是使用服务对其进行管理?
-
我的最终目标是让我的网站在 AWS 上的弹性 beanstalk 中运行。我会在外面想吗?然后我可以有多个 docker 来查询一个数据库。
标签: django postgresql docker