Я настраиваю конвейеры bitbucket для своего проекта Django, чтобы иметь возможность запускать некоторые автоматические тесты.Я использую образ Docker Python по умолчанию с изображением Docker Postgres в качестве службы, но Django не может подключиться к серверу PostgreSQL.Что бы я ни пытался, я всегда получаю сообщение об ошибке:
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
Я пытался задать имя образа localhost / posgres с портом 5432 или без него в моих файлах настроек Django.Также подумал, что, возможно, изображение не показало порт.
мой файл конвейера bitbucket
# This is a sample build configuration for Python.
# Check our guides at https://confluence.atlassian.com/x/x4UWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: python:3.7.3
definitions:
services:
postgres:
image: postgres
environment:
POSTGRES_DB : 'my_db'
POSTGRES_USER : 'my_user'
POSTGRES_PASSWORD: 'my_pwd'
expose:
- "5432"
ports:
- "5432:5432"
pipelines:
default:
- step:
caches:
- pip
script: # Modify the commands below to build your repository.
- pip install -r requirements.txt
# Run tests
- python manage.py test --keepdb
services:
- postgres
мои настройки базы данных Django
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'my_db',
'USER': 'my_user',
'PASSWORD': 'my_pwd',
'HOST': 'localhost',
'PORT': '',
},
'TEST': {
'NAME': 'my_db',
'CHARSET': 'UTF8',
'HOST': 'postgres',
'PORT': '5432'
},
}
Я ожидаю, что мой конвейер сможетподключиться к образу postgres, где работает posgresql.