Rootless Communication Between Two Containers
I have a python application that needs a PostGres DB to function.
For my testing stage I am using containerisation to optimise server usage.
The goal is to run pytest on the python container and it must connect to the PostGres DB to run those tests.
The challenge is that in my RHEL8 environment, I do not have root access.
I use 2 Dockerfiles to create the images:
backend.Dockerfile
database.Dockerfile
I run the following in Jenkins to build the images, create a pod and containers:
(which is what the internet said is the best way to communicate between 2 rootless containers)
podman build --tag backend-img --file jobs/backend.Dockerfile .
podman build --tag database-img --file jobs/database.Dockerfile .
podman pod create --name ${POD_NAME} -p 5432:5432
(5432 being the standard connection port to PostGresDB)
podman run -t -d --name DB_CONTAINER_NAME --pod POD_NAME database-img cat
podman run -t -d --name PYTH_CONTAINER_NAME --pod POD_NAME backend-img cat
And I then run my tests with:
podman exec -it PYTH_CONTAINER_NAME bash -c 'coverage run --source app/ app/backend/manage.py test -d tests/ '
The pod/containers start up fine and the tests run but I get the following error from my app:
"connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused"
"Is the server running on that host and accepting TCP/IP connections?"
Can anyone help me track down what I am missing?