3

I'm using the following docker-compose.yml file:

version: "3.5"

services:
  db:
    image: postgres:latest
    volumes:
      - ./tmp/postgresql/:/var/run/postgresql/:rw
    ports:
      - 5432:5432
    environment:
      POSTGRES_DB: dev
      POSTGRES_USER: username
      POSTGRES_PASSWORD: pw

I can connect to the postgres instance from my host as I have 5432 port forwarded to the host. I wanted to try connecting via the socket, but I am hitting issues. I'm not sure if this is possible?

From my host I can use the following:

psql --host=/Users/jalbert/Projects/postgres-sockets/tmp/postgresql -U username -d dev`

psql: could not connect to server: Connection refused
    Is the server running locally and accepting
    connections on Unix domain socket "/Users/jalbert/Projects/postgres-sockets/tmp/postgresql/.s.PGSQL.5432"?

Although, I do see the socket file present there. If I go within the docker container I can connect via the socket no problem using a similar command.

Am I missing something to allow the host to use the socket connection? Unfortunately, I am not too familiar with the socket technologies.

Kevin Jalbert
  • 3,115
  • 3
  • 26
  • 39

0 Answers0