Access running docker container via network from docker executer

Hi,
I’m running the gitlab-runner in a docker container. I’m using the docker executer and I’m trying to connect an Android Emulator running as docker container. Unfortunately there’s no support for services using devices like /dev/kvm which the Android Emualtor-Container heavily relies on (see this issue and this one). As a worka around I’d like to run the Android Emulator Container on the host and access it via network from the job:

android:test:
    stage: test
    image: xamarin.android:29
    script:
        - apt-get update
        - apt-get install iputils-ping -y
        - ping android-emulator
        - adb connect android-emulator:5555

I can ping the emulator from the gitlab-runner container but the ping within the jobs fails:
ping: android-emulator: Name or service not known

Is this even possible?

Thanks for your help.

The immediate issue is likely that the DNS is not propagating within (but there can be a subsequent issue where the network isn’t setup to access services on the host).

The job runtime cannot resolve android-emulator to any known IP address. You can try manually defining a hosts entry via the extra_hosts docker runner configuration, or try connecting with the IP of the host android-emulator directly if the route permits it.

Thanks for your answer. I looked up the follwing IP adresses:

  • Android Emulator: 172.19.0.3 /16
  • Gitlab Runner: 172.19.0.2/16
  • Job Container: 172.17.0.2/16

So the job container is in a seperate docker network. There’s no routing between docker networks by design (source) . So I can’t ping even using the IP address to exclude DNS problems. But because the port 5555 of the Emulator container is published to the host, I can reach it via host’s IP address with e.g. telnet <IP_HOST> 5555. Firewall was first blocking the connection. On Ubuntu I added the follwing rule to ufw:
sudo ufw allow from 172.16.0.0/12 to any port 5555

It’s working now fine, thank you!