Docker Compose can't connect to PostgreSQL in AWS RDS

Hey, I was able to run my modified twenty code (very lightweight modifications -- not adding new dependencies) locally with the 3 npx commands for server, worker and frontend. Next, I wanted to build it with Docker and use my PostgreSQL database in AWS RDS. So, I ran the Dockerfile (in twenty-docker/twenty). Then, built a new Docker image and used that image (since I had locally made changes to the code) for the docker-compose.yml file (in 'server' & worker 'services') - the only change I made to docker-compose.yml. But, when I run docker compose up, I keep on getting these errors (NOTES at the bottom): [Nest] 1 - 04/17/2025, 2:58:37 AM ERROR [TypeOrmModule] Unable to connect to the database (metadata). Retrying (1)... Error: connect ECONNREFUSED ::1:5432 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) [Nest] 1 - 04/17/2025, 2:58:37 AM ERROR [TypeOrmModule] Unable to connect to the database (core). Retrying (1)... Error: connect ECONNREFUSED ::1:5432 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) [Nest] 1 - 04/17/2025, 2:58:37 AM ERROR [ExceptionHandler] connect ECONNREFUSED ::1:6379 Error: connect ECONNREFUSED ::1:6379 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) NOTES: 1. The db credentials are correct - I verified & can connect to my instance RDS. 2. The RDS instance is correctly configured to receive inbound traffic. 3. I only made 2 changes (mentioned above) to the default docker-compose.yml. Do I need to modify the 'db' service since I'm using my own db instead of the built-in one? Update: I removed 'db' to use my own database but still same issue. 4. docker-compose.yml seems to be pointing to localhost as if something is overriding all my settings about remote db. 5. I verified that my docker-compose.yml file can read from .env file. I even ran with actual details in the yml but same errors. 6. Looking specifically at 'metadata' and 'core' in the error, I even created a database named 'default' in RDS. I also created schemas named 'core' and 'metadata' in the 'default' database. But, still same error. 7. I ran the added the PG_DATABASE_URL env variable during docker build to include it as a build variable. But, still same error. 8. this is my REDIS_URL: redis://redis:6379 How can i fix this? I'd appreciate any help!
2 Replies
Lunorien
Lunorien4d ago
have you verified you enabled cross container network communication? That was my issue. If not, can you send your .env (with redacted secrets) to help debug?
Amiteshwar
AmiteshwarOP3d ago
I'm not sure. How can I check? These are the env variables I'm using related to this: - PG_DATABASE_HOST - PG_DATABASE_PORT - PG_DATABASE_USER - PG_DATABASE_PASSWORD - REDIS_URL It got solved. I had to add ssl to my postgres string for RDS.

Did you find this page helpful?