title: problem with postgres docker container inside Gitlab CI
body: <p>It's been few days I am blocked on this problem with my project, it's working on localhost but not on gitlabCI.
  I would like to build a test database on the postgres docker image in gitlabCI but it doesn't work, I have try a lot of things and lose a lot of hours before ask this there :'(.
  below my docker-compose.yml file :</p>
  <pre><code>version: &quot;3&quot;
  services: 
      nginx: 
          image: nginx:latest
          container_name: nginx
          depends_on: 
              - postgres
              - monapp
          volumes: 
              - ./nginx-conf:/etc/nginx/conf.d
              - ./util/certificates/certs:/etc/nginx/certs/localhost.crt
              - ./util/certificates/private:/etc/nginx/certs/localhost.key
          ports:
          - 81:80
          - 444:443
          networks:
              - monreseau
      monapp:
          image: monimage
          container_name: monapp
          depends_on: 
              - postgres
          ports:
              - &quot;3000:3000&quot;
          networks:
              - monreseau
          command: &quot;npm run local&quot;
  
      postgres:
          image: postgres:9.6
          container_name: postgres
          environment:
              POSTGRES_USER: postgres
              POSTGRES_HOST: postgres
              POSTGRES_PASSWORD: postgres      
          volumes: 
              - ./pgDatas:/var/lib/postgresql/data/
              - ./db_dumps:/home/dumps/
          ports:
              - &quot;5432:5432&quot;
          networks: 
              - monreseau
          
  networks: 
      monreseau:
  </code></pre>
  <p>and below my gitlab-ci.yml file:</p>
  <pre><code>stages:
    # - build
    - test
  
  image: 
    name: docker/compose:latest
  
  services:
  - docker:dind
  
  before_script:
  - docker version
  - docker-compose version 
  
  variables:
    DOCKER_HOST: tcp://docker:2375/
  
  
  # build:
  #   stage: build
  #   script:
  #   - docker build -t monimage .
  #   - docker-compose up -d
  
  test:
    stage: test
    script :
    - docker build -t monimage .
    - docker-compose up -d
    - docker ps
    - docker exec -i postgres psql -U postgres -h postgres -f /home/dumps/test/dump_test_001 -c \\q
    - exit
    - docker exec -i monapp ./node_modules/.bin/env-cmd -f ./env/.env.builded-test npx jasmine spec/auth_queries.spec.js
    - exit
  </code></pre>
  <p>this is the content of docker ps log on gitlabCI server :</p>
  <p><a href="https://i.stack.imgur.com/kIEcv.png" rel="nofollow noreferrer">docker ps on gitlab-CI</a></p>
  <p>I thought to put postgres on host would work, but no I always have in gitlab-ci terminal:</p>
  <pre><code>psql: could not connect to server: Connection refused
      Is the server running on host &quot;postgres&quot; (172.19.0.2) and accepting
      TCP/IP connections on port 5432?
  </code></pre>
  <p>I also tried to put docker on host but error :</p>
  <pre><code>psql: could not translate host name &quot;docker&quot; to address: Name or service not known
  </code></pre>
  <p>little precision : it is working on localhost of my computer when i am doing make builded-test
  bellow my makefile:</p>
  <pre><code>builded-test:
      docker build -t monimage .
      docker-compose up -d
      docker ps
      docker exec -i postgres psql -U postgres -h postgres -f /home/dumps/test/dump_test_001 -c \\q
      exit
      docker exec -i monapp ./node_modules/.bin/env-cmd -f ./env/.env.builded-test npx jasmine spec/auth_queries.spec.js
      exit
      docker-compose down
  </code></pre>
  <p>I want to make work postgres image in my docker-compose on gitlab CI to execute my tests help me please :) thanks by advance</p>
  <hr />
  <p><strong>UPDATE</strong></p>
  <p>Now it working in gitlab-runner but still not on gitlab when I push, I update the files like following</p>
  <p>I added :</p>
  <pre><code>variables:
    POSTGRES_DB: postgres
    POSTGRES_USER: postgres
    POSTGRES_PASSWORD: &quot;&quot;
    POSTGRES_HOST_AUTH_METHOD: trust
  </code></pre>
  <p>and changed</p>
  <pre><code>  test:
    stage: test
    script :
    - docker build -t monimage .
    - docker-compose up -d
    - docker ps
    - docker exec postgres psql -U postgres **-h postgres** -f /home/dumps/test/dump_test_001
    - docker exec monapp ./node_modules/.bin/env-cmd -f ./env/.env.builded-test npx jasmine spec/auth_queries.spec.js
  </code></pre>
  <p>in the .gitlab-ci.yml</p>
  <p>but still don't work when I push it to gitlab, it give me :</p>
  <pre><code>sql: could not connect to server: Connection refused
      Is the server running on host &quot;postgres&quot; (172.19.0.2) and accepting
      TCP/IP connections on port 5432?
  </code></pre>
  <p>any ideas ? :)</p>