-1

I am new to Docker, it is something the team I am on is looking into as we also move to Azure. One of the things I have been trying to do is replicate an existing Postgres database used for local development in a Docker container. I have been successful in doing this, as I have been able to use the psql CLI to run queries in the Postgres container.

One thing I have not been able to figure out is connecting DBeaver to the database in the container. DBeaver currently has a connection to the existing local instance. It looks like the connection setting for the container instance will be the same as the local instance. For example, the host is localhost, the port is 5432, the database is the same name and so the resulting URL would be localhost:5234/mydatabase for both.

I was not sure if this would cause issues, so I tried using a different port for the container instance. In the docker compose I have specified 5434 instead of 5432:

    ports:
      - '5434:5434'

So for the connection settings I specified 5434 instead of the default 5432, resulting in the URL localhost:5434/mydatabase. When I click 'Test Connection...' I get the following error:

The connection attempt failed.
  EOFException
  java.io.EOFException

Searching on this error I came across things that said drivers needed to be updated, but this is working fine for the local instance of the database. When I look at the properties for the Postgres driver, on the Native Client tab the product version is listed as "psql (PostgreSQL) 13.3. In the Docker compose file, the postgres:13.3-alpine image is specified. For both connections (local and container), DBeaver put the following at the beginning of the URL - jdbc:postgresql://. So I am not sure if this matters.

I am at a loss on why I cannot get DBeaver to connect to the container instance of Postgres, and don't want to mess up the existing connect to the local instance. Any suggestions are appreciated.

Thank you!

Ray Koziel
  • 11
  • 2
  • Does this answer your question? [How to connect to a database running in docker in a digital ocean droplet remotely?](https://stackoverflow.com/questions/76001012/how-to-connect-to-a-database-running-in-docker-in-a-digital-ocean-droplet-remote) – Don't Panic Jun 11 '23 at 07:47
  • @dont-panic If I followed the steps in the link correctly, I set the port in the compose file so that it is '5432:5432'. When I try to connect with DBeaver and specify the port as 5432 then it connects to the existing local database and not the container instance. If I try to remap the port for example '5434:5432' and update the connection in DBeaver to use 5434 I still get the error noted above. – Ray Koziel Jun 16 '23 at 19:23

1 Answers1

0

If you want to re-map the default port, edit the ports configuration in a way that the default port 5432 will be forwarded to your custom port 5434:

 ports:
  - '5434:5432'

For seek of clarity, I write you an example of docker-compose.yaml file that use the indicated ports:

volumes:
  volume_name:
    name: volume_name
services:
  db:
    image: postgres:latest
    user: postgres
    environment:
     - POSTGRES_PASSWORD=postgres
     - POSTGRES_USER=postgres
     - POSTGRES_DB=postgres-db
    ports:
      - "5434:5432"
    volumes:
      - volume_name:/var/lib/postgresql/data

You can run it with docker compose up.

To connect:

  • on another terminal type psql -U postgres -p 5434 -h localhost to connect
  • with DBeaver set this arguments: host: localhost, Database: postgres-db, Port: 5434, Username: postgres, Password: postgres
Alez
  • 1,913
  • 3
  • 18
  • 22
  • I finally was able to try this. In the compose file I set ports as specified: '5434:5432'. In DBeaver, if I set the port to 5434 for the connection settings I still get the exception noted above. If I set the port to 5432 then it is just setting a second connection to the existing local database. – Ray Koziel Jun 16 '23 at 19:13
  • I updated the answer in order to allow you to have a working example about what I suggested. – Alez Jun 17 '23 at 00:56
  • Thanks for the update. I've been able to connect using the psql CLI so that is not the issue. I am trying to connect using DBeaver as I would prefer to use that instead of the CLI. – Ray Koziel Jun 19 '23 at 14:26
  • If you can connect with psql you must be able to connect also with DBeaver. I updated my answer also with the arguemnts for DBeaver. – Alez Jun 19 '23 at 14:39