title: Find url/ip of container running in docker-compose in gitlab ci
body: <p>I have an application that runs in docker-compose (for acceptance testing).  The acceptance tests work locally, but they require the host (or ip) of the webservice container running in docker-compose in order to send requests to it.  This works fine locally, but I cannot find the ip of the container when it is running in a gitlab ci server.  I've tried the following few solutions (all of which work when running locally, but none of which work in gitlab ci) to find the url of the container running in docker-compose in gitlab ci server:</p>
  <ol>
  <li>use &quot;docker&quot; as the host.  This works for an application running in docker, but not docker-compose</li>
  <li>use docker-inspect to find the ip of the container (<em>docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' reading-comprehension</em>)</li>
  <li>assign a static ip to the container using a network in docker-compose.yml (latest attempt).</li>
  </ol>
  <p>The gitlab ci file can be found here:
  <a href="https://gitlab.com/connorbutch/reading-comprehension/-/blob/9-list-all-assessments/.gitlab-ci.yml" rel="nofollow noreferrer">https://gitlab.com/connorbutch/reading-comprehension/-/blob/9-list-all-assessments/.gitlab-ci.yml</a></p>
  <pre><code>    image: connorbutch/gradle-and-java-11:alpha
  
  variables:
    GRADLE_OPTS: &quot;-Dorg.gradle.daemon=false&quot;
    DOCKER_HOST: &quot;tcp://docker:2375&quot;
    DOCKER_DRIVER: &quot;overlay2&quot;
  
  before_script:
    - export GRADLE_USER_HOME=`pwd`/.gradle
  
  services:
    - docker:stable-dind
  
  stages:
    - build
    - docker_build
    - acceptance_test
  
  unit_test:
    stage: build
    script: ./gradlew check
    cache:
      key: &quot;$CI_COMMIT_REF_NAME&quot;
      policy: pull
      paths:
        - build
        - .gradle
  
  build:
    stage: build
    script:
      - ./gradlew clean quarkusBuild
      - ./gradlew clean build -Dquarkus.package.type=native -Dquarkus.native.container-build=true
    cache:
      key: &quot;$CI_COMMIT_REF_NAME&quot;
      policy: push
      paths:
        - build
        - .gradle
    artifacts:
      paths:
        - reading-comprehension-server-quarkus-impl/build/
  
  docker_build:
    stage: docker_build
    script:
      - cd reading-comprehension-server-quarkus-impl
      - docker build -f infrastructure/Dockerfile -t registry.gitlab.com/connorbutch/reading-comprehension:$CI_COMMIT_SHORT_SHA  .
      - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
      - docker push registry.gitlab.com/connorbutch/reading-comprehension:$CI_COMMIT_SHORT_SHA
  
  acceptance_test:
    stage: acceptance_test
    only:
      - merge_requests
    script:
      - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
      - cd reading-comprehension-server-quarkus-impl/infrastructure
      - export IMAGE_TAG=$CI_COMMIT_SHORT_SHA
      - docker-compose up -d &amp; ../../wait-for-it-2.sh
      - cd ../..
      - ./gradlew -DBASE_URL='192.168.0.8' acceptanceTest
    artifacts:
      paths:
        - reading-comprehension/reading-comprehension-server-quarkus-impl/build/
  </code></pre>
  <p>The docker-compose file can be found here:
  <a href="https://gitlab.com/connorbutch/reading-comprehension/-/blob/9-list-all-assessments/reading-comprehension-server-quarkus-impl/infrastructure/docker-compose.yml" rel="nofollow noreferrer">https://gitlab.com/connorbutch/reading-comprehension/-/blob/9-list-all-assessments/reading-comprehension-server-quarkus-impl/infrastructure/docker-compose.yml</a></p>
  <p>Find the output of one of the failed jobs here:
  <a href="https://gitlab.com/connorbutch/reading-comprehension/-/jobs/734771859" rel="nofollow noreferrer">https://gitlab.com/connorbutch/reading-comprehension/-/jobs/734771859</a></p>
  <pre><code>#This file is NOT ever intended for use in production.  Docker-compose is a great tool for running
  #database with our application for acceptance testing.
  version: '3.3'
  
  networks:
    network:
      ipam:
        driver: default
        config:
          - subnet: 192.168.0.0/24
  
  services:
    db:
      image: mysql:5.7.10
      container_name: &quot;db&quot;
      restart: always
      environment:
         MYSQL_DATABASE: &quot;rc&quot;
         MYSQL_USER: &quot;user&quot;
         MYSQL_PASSWORD: &quot;password&quot;
         MYSQL_ROOT_PASSWORD: &quot;password&quot;
         MYSQL_ROOT_HOST: &quot;%&quot;
      networks:
        network:
          ipv4_address: 192.168.0.4
      ports:
        - '3306:3306'
      expose:
        - '3306'
      volumes:
        - db:/var/lib/mysql
    reading-comprehension-ws:
      image: &quot;registry.gitlab.com/connorbutch/reading-comprehension:${IMAGE_TAG}&quot;
      container_name: &quot;reading-comprehension&quot;
      restart: on-failure
      environment:
        WAIT_HOSTS: &quot;db:3306&quot;
        DB_USER: &quot;user&quot;
        DB_PASSWORD: &quot;password&quot;
        DB_JDBC_URL: &quot;jdbc:mysql://192.168.0.4:3306/rc&quot;
      networks:
        network:
          ipv4_address: 192.168.0.8
      ports:
        - 8080:8080
      expose:
        - 8080
  volumes:
    db:
  </code></pre>
  <p><strong>Does anyone have any idea on how to access the ip of the container running in docker-compose on gitlab ci server?  Any suggestions are welcome.</strong></p>
  <p>Thanks,</p>
  <p>Connor</p>