Ansh Godha
Ansh Godha

Reputation: 13

Postgres running via docker not persisting data after initialization script

I'm using docker for the first time to set up a test database that my team can then use. I'm having some trouble getting my data on DBeaver after running my docker-compose file. The issue I'm facing is that my database does not show up in DBeaver (along with relevant Schemas and Tables that I also create/populate in my initialization sql script).

Here is my docker-compose.yml

version: "3"
services:
  test_database:
    image: postgres:latest
    build:
      context: ./
      dockerfile: Dockerfile
    restart: always
    ports:
      - 5432:5432
    environment:
      - POSTGRES_USER=dev
      - POSTGRES_PASSWORD=test1234
      - POSTGRES_DB=testdb
    container_name: test_database

In this, I specify the docker file I want it to use for building. Here is the dockerfile:

# syntax = docker/dockerfile:1.3
FROM postgres:latest

ADD test_data.tar .

COPY init_test_db.sql /docker-entrypoint-initdb.d/

Now, when I run docker-compose build and docker-compose up, I can see through the logs that my SQL commands (CREATE, COPY, etc.) do get executed and the rows do get added. But when I connect to this instance through DBeaver, I can't see this at all. In fact, the only database on there is the default Postgres database, even through the logs say I'm connected to test_database.

I followed some other solutions and used docker volume prune as well, but that didn't affect anything (I read some solutions about clearing up volumes, and at that point, I had volumes: /tmp:/tmp as well). Any ideas?

Upvotes: 0

Views: 433

Answers (1)

Ansh Godha
Ansh Godha

Reputation: 13

Wow, this wasn't an error after all. All I had to do was go on the connection settings on DBeaver and check 'Show all databases' under the Postgres tab. Hope this can help someone :)

Upvotes: 1

Related Questions