0

I want the data_dump.sql to load when the container is first created I do not want it to dump data the second time when the container is stopped and started again, But first I am not even able to load by database dump in my database even when it is started.

I have added a volume in the Postgres service with data_dump_sql file but it was not loaded into the database even when I started the containers with docker-compose up(I even tried fully stoping the containers with docker-compose down) and started them again but the data has not been added into the database.

version: "3.8"

services:
  postgres:
    image: postgres:latest
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=root
      - POSTGRES_DB=nanomedicine_db
    ports:  #outside:inside(container)
      - 5432:5432
    networks:
      - shared-network
    volumes:
      - postgres-volume:/var/lib/postgresql/data
      - ./devops/db/dummy_dump.sql:/docker-entrypoint-initdb.d/dummy_dump.sql
      # - ./backup-files:/backup-files

  pgadmin:
    container_name: pgadmin4_container
    image: dpage/pgadmin4
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: root
    ports:
      - 5050:80
    networks:
      - shared-network
    depends_on:
      - postgres
    volumes:
      - pgadmin-volume:/var/lib/pgadmin
  
  nginx:
    container_name: nginx_container
    restart: always
    build:
      context: ./nginx
      dockerfile: Dockerfile
    ports:
      - 3050:90
    networks:
      - shared-network
    depends_on:
      - server
      - client

  server:
    container_name: nanomedicine_server
    restart: unless-stopped
    image: nanomedicine-server-image:1.0.0
    build:
      context: nanomedicine-backend 
      target: production
      dockerfile: Dockerfile
    ports:  #outside:inside(container)
      - 8080:8080
    networks:
      - shared-network
    depends_on:
      - postgres

  client:
    container_name: nanomedicine_client
    restart: unless-stopped
    image: nanomedicine-client-image:1.0.0
    build:
      context: nanomedicine-frontend 
      target: production
      dockerfile: Dockerfile
    ports:  #outside:inside(container)
      - 3000:3000

    networks:
      - shared-network
    depends_on:
      - server
volumes:
  postgres-volume:
  pgadmin-volume:
networks:
  shared-network:

Data in SQL dump

I have created a dummy sql file with dummy data so that I can check if a table with data will be created in my already existing database with peristant data because of volumes. I was expecting a new table called 'dummyTable' to appear in pgadmin tables but only the old tables from postgres-volume are appering.

This is the pgadmin image of all tables available in pgadmin of docker. docker pgadmin

To get a way to populate my posgress database in docker to populate automatically through docker compose

  • When you tried running `docker-compose up`, had the database been previously initialized; did you run `docker-compose down -v` first? You seem to have rendered your database dump into a PNG file, and the database load scripts won't understand that; do you have that in a plain-text SQL file? Is there anything interesting in the container logs? – David Maze Jul 06 '23 at 22:49
  • official postgres image doesn't load the data if data already exists – erik258 Jul 06 '23 at 22:49
  • @DavidMaze the dummy_dump.sql is working now with that file database in docker if use docker-compose down -v (to even delete volumes). But there is a new problem the SQL file is only working for simple SQL files. It's not working for backup sql files that we use for restoring any possible work though to load backup sql files to directly dump in the database through docker-compose like this? – Nithin_Kamineni Jul 06 '23 at 23:52

0 Answers0