Accessing PostgreSQL inside container

Hi everyone,

I have a problem with the postgres service inside the GitLab CI image. I need PostgreSQL for my tests to run, but while it seems that the database is started, I cannot connect to it (on localhost:5432). Is some other port default there? Or am I missing something? My YAML file:

image: java:8

services:

  • postgres:latest

variables:
GRADLE_OPTS: “-Dorg.gradle.daemon=false”
POSTGRES_DB: kundenportal
POSTGRES_USER: postgres
POSTGRES_PASSWORD: “admin”

before_script:
- chmod +x gradlew

build:
stage: build
script:
- ./gradlew -g /cache/.gradle clean assemble
allow_failure: false

test:
stage: test
script:
- ./gradlew -g /cache/.gradle test --debug
allow_failure: false

Try connecting to the hostname postgres instead of localhost.

See https://docs.gitlab.com/ce/ci/docker/using_docker_images.html#how-services-are-linked-to-the-job

1 Like