'How to Access Postgres Service from Child Docker Container in Gitlab-CI? How do I access IP address of postgres service or gitlab shared runner?
I have setup a gitlab-ci build with the architecture illustrated below.
(source: gitlab.com)
.
The listener container is unable to communicate with the postgres container using the hostname, ‘postgres’. The hostname is unrecognised. How can the listener container communicate with the postgres database instance?
The documentation recommends configuring a postgres instance as a service in .gitlab-cy.yml. CI jobs defined in .gitlab-ci.yml, are able to connect to the postgres instance via the service name, 'postgres'.
The tusd, minio and listener containers are spawned within a docker-compose process, triggered inside the pytest CI job. The listener container writes information back to the postgres database.
Subsequently, I thought about using the IP address of the postgres service in place of the hostname. From within the pytest CI build job I have tried to determine the IP address of the postgres database using the following bash command sequence:
- export DB_IP="$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' postgres)"
- echo "DB IP ADDRESS IS $DB_IP"
However, postgres is not recognised as a container.
How do I determine the IP address of the postgres service? Alternatively can I use the IP address of the shared runner? How do I determine this?
Does anybody have any ideas?
Update 11/1/2019 Resolved by moving all services into docker-compose file so that they can communicate with each other. This includes the postgres container etc…After some refactoring in test environment initialisation, tests are now invoked via docker-compose run command.
Now able to successfully run tests using gitlab-shared runner…
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|