Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker-compose Adding Postgres Password

I'm having issues accessing my postgres db from my remote machine. I'm running docker-compose (django and postgres) from a digitalOcean droplet, so I need to be able to access the db from my mac.

I thought the below would work based on the outline of environment usage in docker-compose. Any help would be appreciated.

db:
  image: postgres
  ports:
    - "5555:5555"
  environment:
    - POSTGRES_PASSWORD=mysecretpassword
    - POSTGRES_USER=postgres
web:
  build: .
  command: python manage.py runserver 0.0.0.0:8000
  volumes:
    - .:/code
  ports:
    - "8000:8000"
  links:
    - db

I'm trying to access the postgres db from pgadmin3 on port 5555, user:postgres, pass:mysecretpassword.

like image 948
Tyler B. Wear Avatar asked Oct 31 '22 07:10

Tyler B. Wear


1 Answers

Postgres uses port 5432 by default. You can map the 5432 port within the container to the host post of 5555 with a colon (as shown below).

db:
  image: postgres
  ports:
    - "5555:5432"
  environment:
    - POSTGRES_PASSWORD=mysecretpassword
    - POSTGRES_USER=postgres

You're database is now accessible via port 5555.

I haven't used pgAdmin, but with psql the database can be accessed with...

psql -U postgres -h <your ip> -p 5555
like image 58
seveibar Avatar answered Nov 15 '22 07:11

seveibar