Doid in drone not reaching service

I have an interesting problem.
We have a container running docker in drone to test an ansible script using molecule.

This script works fine on our old docker runner, but on another server it fails: the container started by drone can reach the service, but the container started from that container can not.

Any clues what could be the cause? I’m trying to figure out if there are any differences between the environments (eg docker/docker-runner version), but no luck until now.

    ---
    kind: pipeline
    type: docker
    name: molecule_build
    concurrency:
      limit: 1
    steps:
      - name: test using molecule
        image: xxx/molecule
        commands:
          - "export PGSQL_HOST=$(nslookup pgsql | sed -n -e 's/Address: //p')"
          - echo $PGSQL_HOST
          - cd ansible/roles/cable_alert
          - molecule test
        volumes:
          - name: docker_socket
            path: /var/run/docker.sock
        privileged: true
        environment:
          MOLECULE_NO_LOG: "true"
          GITEA_TOKEN: 
            from_secret: GITEA_TOKEN
    services:
     - name: pgsql
       image: kartoza/postgis:12.0
    volumes:
        - name: docker_socket
          host:
            path: /var/run/docker.sock

using the same drone version does not solve the issue. Docker version is also identical (20.10.5)

@johanvdw ,

Could you please enable debug logging and share the server/runner logs with us for our reveiw.

Regards,
Harness Support

I managed to find a workaround.

First in our .drone file, we get the network of the running container:

export NETWORKID=$(docker inspect $HOSTNAME -f "{{range .NetworkSettings.Networks }}{{println .NetworkID}}{{end}}" | head -n1)

Then inside our default/molecule.yml file we make sure that the new created docker is inside the same network as the container created by drone:

molecule/default/molecule.yml

---
dependency:
  name: galaxy
driver:
  name: docker
platforms:
  - name: instance
    image: python:3.7-buster
    pre_build_image: true
    network_mode: $NETWORKID