I'm running a PostgreSQL instance in a Docker container named postgres_server.development.ch_api and using another Docker container for my Express app called express_server.development.ch_api. I'm trying to set up self-signed SSL certificates for PostgreSQL using OpenSSL, following the guidelines from the official PostgreSQL documentation. The issue I'm facing is that when I set the Common Name (CN) to 'localhost', my Express and PostgreSQL containers can't communicate with each other. Conversely, if I use the container name as the CN, I can't connect to the PostgreSQL server from my local machine due to a CN mismatch. How can I configure it so that it works correctly for both situations?
1 Answer
It sounds like you're dealing with a classic networking issue between Docker containers. One solution is to create a dedicated Docker network and add both your Express and PostgreSQL containers to that network. This way, they can communicate with each other using their hostnames. For connecting from your local machine, you should expose the PostgreSQL port and access it using your local IP address followed by the port number.

The containers are fine working together, but the issue is that I can’t access the PostgreSQL container from my local machine. I'm getting an error that says it can't translate the hostname 'postgres_server.development.ch_api'. If I change the CN to 'localhost' in the OpenSSL config, then it connects just fine, but then the containers can't see each other.