1

I am using this docker-compose to spin up a postgres instance on my laptop. It works fine when I connect it as localhost. However, I would like to connect to it from a different laptop but i'm not able to. In the postgresql.conf file, the listening address is set to * already and I also added the this line host all all 0.0.0.0/0 md5 to pg_hba.conf. When I connect to it locally with DBeaver, it only works with localhost or 0.0.0.0 as host but doesn't work when I change it to the container IP. What am I missing here?

docker-compose.yml

services:
  database:
    image: postgres
    ports:
      - "5432:5432"
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: mydb
    user: postgres
    volumes:
       - pgdata:/var/lib/postgresql/data
volumes:
  pgdata:
qweq
  • 83
  • 1
  • 7
  • 1
    You shouldn't need to change anything in the container, to be able to reach it from another machine. My guess is that the firewall in your container host is blocking connections from outside. – Hans Kilian May 12 '22 at 06:05
  • the container IP is a private IP that only exists within a given docker network. – The Fool May 12 '22 at 06:06
  • If the 2 laptops are not on the same network, you will probably not get to your app. Home routers are usually not exposed to the internet. There are tools like [ngrok](https://ngrok.com/) but I would not advice to use them. Its probably better to rent a vps for 5 bugs. – The Fool May 12 '22 at 06:09
  • Sorry for the dumb question but does the container need to be hosted on an actual server for it to work? Right now the container is just on a regular Laptop. – qweq May 12 '22 at 06:23
  • That is what I am talking about in my second comment. Technically speaking no, you dont need a real server. You can do this with a laptop. Especially if they are in the same network i.e. they are both connected to your router at home. If they are not on the same router, there are ways to expose it to the public internet but I would not recommend doing that. – The Fool May 12 '22 at 06:26

0 Answers0