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?
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.
How can I get the host ip in a docker container using Python?