I am trying to spin up a Postgres service and access it from within a docker container. This is my .gitlab-ci.yml:
image: docker:dind
stages:
- build
services:
- docker:dind
- postgres:11-alpine
variables:
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_DB: gitlabci
build_and_test:
when: manual
stage: build
script:
- docker run --rm postgres psql postgresql://postgres@postgres/gitlabci -c "SELECT 1;"
however, when I run this job I get an error:
psql: error: could not translate host name "postgres" to address: Name or service not known
How do I specify hostname from within a docker container?
docker-compose upin the ci. The service name you give in docker-compose will be the hostname you can use to connect to it. Then you simply create ci env variables that have those hostnames as the value so your other services can connect to it.