Accessing a Docker container service from another container service (hosts and network) - GitLab CI trials and tribulations

In GitLab CI, I want to be able to access a container listed under services from another container listed under services. Unfortunately, it doesn't seem possible yet because services hosts are not shared to the other services containers (see "Access a service host in another service" below"). And there isn't a way to define a network that the container should belong to with the services syntax.

image: node:boronvariables:docker.for.mac.localhost hostname via https://stackoverflow.com/a/43541732/796832s$DOCKER_REGISTRY = registry.gitlab.com or docker.for.mac.localhost:5063$IMAGE_NAMESPACE = gitlab-org/gitlab-selenium-server or root/gitlab-selenium-serverWe have to separate this instead of constructing from $DOCKER_REGISTRY and $IMAGE_NAMESPACEbecause docker.for.mac.localhost:5063/root/gitlab-selenium-server:latest doesnot work because the host should be localhost ¯_(ツ)_/¯$IMAGE_FULL_NAME = registry.gitlab.com/gitlab-org/gitlab-selenium-server or localhost:5063/root/gitlab-selenium-serverstages:buildtestbuild-docker-image:stage: buildimage: docker:latestvariables:DOCKER_DRIVER: overlay2script:- docker info- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $DOCKER_REGISTRY- docker build -t $DOCKER_REGISTRY/$IMAGE_NAMESPACE:test --file="Dockerfile" .- docker push $DOCKER_REGISTRY/$IMAGE_NAMESPACE:testservices:- name: docker:dindcommand:- "--insecure-registry"# Unable to use $DOCKER_REGISTRY because it doesn't seem to work :/# See https://gitlab.com/gitlab-org/gitlab-ce/issues/38346- "docker.for.mac.localhost:5063"tags:- docker- sharedTHIS DOES NOT WORK.HOSTS ARE NOT ACCESSIBLE IN ANOTHER SERVICEtest-docker-image:stage: testscript:# The GitLab Selenium Proxy fails to find the target http://actual-selenium-server:4444/wd/hub- curl http://gitlab-selenium-proxy:4444/ || true- curl http://gitlab-selenium-proxy:4444/wd/hub/status || true- curl http://gitlab-selenium-proxy:4444/logs || truevariables:SELENIUM_REMOTE_URL: http://gitlab-selenium-proxy:4444/wd/hubGITLAB_TARGET_SELENIUM_REMOTE_URL: http://actual-selenium-server:4444/wd/hubservices:# To figure out the host name of a service, see https://docs.gitlab.com/runner/executors/docker.html#accessing-the-services# ---## See https://github.com/SeleniumHQ/docker-selenium- name: selenium/standalone-chrome:3.4.0-francium# For reference, the default host is selenium__standalone-chrome:4444alias: actual-selenium-server- name: $IMAGE_FULL_NAME:test# For reference, the default host is when using a local registry, localhost__root__gitlab-selenium-server__selenium-server:4444alias: gitlab-selenium-proxytags:- docker- shared

Create an image with the service already inside ✔

Another alternative is to create an image FROM selenium/standalone-chrome:3.4.0-francium
and include everything it needs(like Node and npm) inside so you can just use it as a GitLab CI service.

This is probably the cleanest solution that actually works at the moment.
BUT it bloats the image size, stuck to a single Selenium Server in this case Chrome(unless we want to pack things ourselves), and there isn't a slick way to merge two images together because there can't be two separate base images (ideally just merge node:boron and selenium/standalone-chrome:3.4.0-francium)

Using Docker in Docker (dind) ✔

Running our own Docker in Docker (dind) image, we can setup a network that will share the host names. But this is cumbersome and requires a lot of extra boilerplate. And from my testing, seems a bit flakey even with the explicit waits for running and sleep times.