0

I'm fairly new to Docker and I'm trying to create a Django development container. I have Postgres database running on my PC on port 5432.

I run this command:

docker run --env-file .env.dev -p 127.0.0.1:5432:5432 test sh -c "python manage.py makemigrations && python manage.py migrate"

Which returns:

Error starting userland proxy: listen tcp4 127.0.0.1:5432: bind: address already in use.

I understand that host port 5432 is already in use by Postgres but AFAIK I should map dockers 5432 to 5432 to be able to connect to the database, shouldn't I?

Milano
  • 18,048
  • 37
  • 153
  • 353
  • The `-p` option is for accepting connections _into_ your container; so if you were running a `postgres:13` container, for example. You don't need a special option to make connections _out_ of your container. (I marked this as a duplicate of the canonical question for this error message, but also see [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) to connect to a non-Docker database on the same host.) – David Maze Apr 30 '21 at 12:40
  • @DavidMaze I tried --network="host" when running container and it says: django.db.utils.OperationalError: could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432? – Milano Apr 30 '21 at 12:57

0 Answers0