TKems
TKems

Reputation: 109

Error connecting to RDS Postgreql DB from inside Docker container

I've got an app running Flask_sqlalchemy in a Docker container.

The container wasn't running properly so I dived in and tried running the application and get the following error:

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
    Is the server running on host "DBNAME.XXXXXXXXXX.eu-west-1.rds.amazonaws.com" (000.000.000.000) and accepting
    TCP/IP connections on port 5432?

The application works fine outside the container, and I can't work out what's going on.

Could it be something to do with the AWS-RDS security groups? They're currently configured to only accept inbound connections from our office where development takes place.

EDIT:

This is my Dockerfile:

FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential libpq-dev python-shapely
COPY . /src
WORKDIR /src

RUN pip install -r requirements.txt

EXPOSE 5000
CMD ["python", "application.py"]

And this is the Docker Run command I'm doing:

docker run -d -p 5000:5000 container_name

Thanks

Upvotes: 0

Views: 1570

Answers (1)

WGra
WGra

Reputation: 46

I had exactly the same problem ;) but solved it by ensuring the following:

  • The AWS ELB environment configuration is Generic Docker (not preconfigured for Python).
  • The environment is created inside of a VPC that contains the RDS instance.
  • The RDS instance is listening to the right port (PostgreSQL:5432) from the VPC security group (this should already be the case).

Upvotes: 2

Related Questions