GitlabCi dependency between services

Summary

I'm trying to use a docker image (APP) from gitlab private registry as a gitlabci service. **This image need a database server (mysql). ** I want another service to be used as database server by the APP (link)

Steps to reproduce

This is the Dockerfile of (APP)

FROM ruby:2.4
MAINTAINER jbo@company.com

ARG APPLICATION_NAME
ARG APPLICATIONS_PATH
ARG RAILS_ENV
ARG MYSQL_DATABASE
ARG MYSQL_USER


# Install dependencies
RUN apt-get update && apt-get install -y \
  build-essential \
  nodejs htop mc python-software-properties \
  git-core curl wget vim sudo apt-transport-https mysql-client

# Configure main working directory.
RUN mkdir -p $APPLICATIONS_PATH/$APPLICATION_NAME
WORKDIR $APPLICATIONS_PATH/$APPLICATION_NAME

# Copy the Gemfile as well as the Gemfile.lock and install
# the RubyGems. This is a separate step so the dependencies
# will be cached unless changes to one of those two files
# are made.
COPY Gemfile Gemfile.lock ./
RUN gem install bundler && bundle install --jobs 20 --retry 5

# Copy the main application.
COPY . ./

RUN sed -i '/  password: root/s/.*/&\n  host: mysql/' config/database.yml

RUN cat config/database.yml

# Expose port 3000 to the Docker host, so we can access it
# from the outside.
EXPOSE 3000 

CMD ["bundle", "exec", "rake", "db:create" ]
CMD ["bundle", "exec", "rake", "db:migrate"]

# The main command to run when the container starts. Also
# tell the Rails dev server to bind to all interfaces by
# default.
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]

My .gitlab-ci.yml with the two services:

stages:
- test

services:
- mysql:5.7
- cloud.toto.com:4567/myapp/api:develop

variables:
  RAILS_ENV: development
  MYSQL_DATABASE: myapp_dev
  MYSQL_ROOT_PASSWORD: root
  MYSQL_USER: myapp

run_api:
  stage: test
  tags:
    - nodind
  script:
    - curl 127.0.0.1:3000

Actual behavior

APP thow an error Unknown MySQL server host 'mysql' (25) (Mysql2::Error). It seems there is no "link" between them.

Running with gitlab-ci-multi-runner 9.1.1 (6104325)
  on runner_ovh-nodind (d8fe831c)
Using Docker executor with image docker:latest ...
Starting service mysql:5.7 ...
Pulling docker image mysql:5.7 ...
Using docker image mysql:5.7 ID=sha256:9e64176cd8a206f88336506fe52cd8f87423147dc197d0250175dddc39465e90 for mysql service...
Starting service cloud.toto.com/myapp/api:develop ...
Pulling docker image cloud.toto.com:4567/myapp/api:develop ...
Using docker image cloud.toto.com:4567/myapp/api:develop ID=sha256:7e88e29e16060e559e087da243e104f5dccabefa064ff2312cff83a08269ffc9 for cloud.toto.com/myapp/api service...
Waiting for services to be up and running...

*** WARNING: Service runner-d8fe831c-project-145-concurrent-0-cloud.toto.com__myapp__api probably didn't start properly.

service runner-d8fe831c-project-145-concurrent-0-cloud.toto.com__myapp__api-wait-for-service did timeout

2017-05-08T13:49:54.991837707Z /var/www/apps/myapp/config/initializers/fcm.rb:3: warning: already initialized constant FCM
2017-05-08T13:49:54.991922789Z /usr/local/bundle/gems/fcm-0.0.2/lib/fcm.rb:5: warning: previous definition of FCM was here
2017-05-08T13:49:55.203374560Z /usr/local/bundle/gems/mysql2-0.4.5/lib/mysql2/client.rb:89:in `connect': Unknown MySQL server host 'mysql' (25) (Mysql2::Error)
2017-05-08T13:49:55.203408651Z 	from /usr/local/bundle/gems/mysql2-0.4.5/lib/mysql2/client.rb:89:in `initialize'
...

I try this workaround but I get an error:

docker run -p $MYSQL_PORT_3306_TCP_ADDR:$MYSQL_PORT_3306_TCP_PORT:3306 -p 3000:3000 cloud.toto.com:4567/myapp/api:develop
docker: Error response from daemon: driver failed programming external connectivity on endpoint heuristic_jang (5a66eed5c069423126f0ac04af45708d8936c9d0c92689331724dbbfa0388a46): Error starting userland proxy: listen tcp 172.17.0.2:3306: bind: cannot assign requested address.

Expected behavior

I expect APP service to be able to contact mysql service.

Environment description

Custom install, tested with differents runner config:

[[runners]]
  name = "runner_ovh-nodind"
  url = "https://cloud.toto.com/ci"
  token = "d8fe831c9e6bc9e90737fe5dcbd856"
  environment = [ "GITLAB_RUNNER_TOKEN=ddsssssssssssssss" ]
  executor = "docker"
  [runners.docker]
    image = "docker:latest"
    privileged = true
    disable_cache = false
    cap_drop = [ "NET_ADMIN", "SYS_ADMIN", "DAC_OVERRIDE" ]
    volumes = [ "/var/run/docker.sock:/var/run/docker.sock" ]
[[runners]]                                                                                                                                                                     
  name = "runner_ovh-docker"                                                                                                                                                    
  url = "https://cloud.toto.com/ci"                                                                                                                                               
  token = "f5088983b120eb49654b487cc4edf0"                                                                                                                                      
  environment = [ "GITLAB_RUNNER_TOKEN=ddssdffsdsddddddddddddd" ]                                                                                                                  
  executor = "docker"                                                                                                                                                           
  [runners.docker]                                                                                                                                                              
    image = "docker:latest"                                                                                                                                                     
    privileged = true                                                                                                                                                           
    disable_cache = false
    cap_drop = [ "NET_ADMIN", "SYS_ADMIN", "DAC_OVERRIDE" ]
docker info 
Containers: 2
 Running: 0
 Paused: 0
 Stopped: 2
Images: 16
Server Version: 17.04.0-ce
Storage Driver: overlay
 Backing Filesystem: extfs
 Supports d_type: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins: 
 Volume: local
 Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: 
containerd version: 422e31ce907fd9c3833a38d7b8fdd023e5a76e73
runc version: 9c2d8d184e5da67c95d601382adf14862e4f2228
init version: 949e6fa
Kernel Version: 4.9.0-0.bpo.2-amd64
Operating System: Debian GNU/Linux 8 (jessie)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.769GiB
Name: runner_ovh
ID: G67E:C565:XJT6:GO46:2BQO:2LDX:DFOO:4RFH:NC3S:O7MJ:GIPD:QTV6
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Used GitLab Runner version

gitlab-runner -v
Version:      9.1.1
Git revision: 6104325
Git branch:   9-1-stable
GO version:   go1.7.5
Built:        Tue, 02 May 2017 10:43:57 +0000
OS/Arch:      linux/amd64