2

Context: I implemented tests which use docker-py to create docker networks and run docker containers. The test runner used to execute the tests is pytest. The test setup depends on Python (Python package on my dev machine), on my dev machines docker daemon and my dev machines static ip address. In my dev machine runtime context the tests run just fine (via plain invocation of the test runner pytest). Now I would like to migrate the tests into gitlab-ci. gitlab-ci runs the job in a docker container which accesses the CI servers docker daemon via /var/run/docker.sock mount. The ip address of the docker container which is uses by gitlab-ci to run the job in is not static like in my dev machine context. But for the creation of the docker networks in the test I need the ip address.

Question: How can I get the appropriate ip address of the docker container the tests are executed in with Python?

thinwybk
  • 4,193
  • 2
  • 40
  • 76
  • 1
    Why not use docker's DNS for connectivity between containers? – BMitch Aug 01 '18 at 09:47
  • The containers wrap "nodes" (executable processes for robotics functionality) of the Robot Operating System. These "nodes" act as single processing entities in a network and implement robotic applications in the bigger scope. To come to the point: It's not straightforward to enable DNS for ROS node networks in the CI test context I guess. – thinwybk Aug 01 '18 at 10:17

1 Answers1

-1
  • When you run docker you can share the same network as the host if asked.
  • Add to the run command --network host
  • Such parameter will cause the python network code be the same as you run the code without container.
Oron Golan
  • 361
  • 1
  • 13
  • I create [`bridge` networks for the containers with docker-py](https://docker-py.readthedocs.io/en/stable/networks.html) which are incompatible with `--network host`. – thinwybk Aug 01 '18 at 10:20