0

I know this question is already asked here and also answer given. But it is not working for me. I follow the same. My postgres container is running fine. I checked inside the container that /docker-entrypoint-initdb.d/init.sql exist.I used the following docker-compose.yml.

version: "3"
services:
  postgres:
    image: postgres:latest
    network_mode: bridge
    container_name: postgres
    expose:
    - 5432
    ports:
      - 5432:5432
    volumes:
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    environment:
         - POSTGRES_PASSWORD=admin
         - POSTGRES_USER=postgres
         - POSTGRES_DB=dev
    restart: unless-stopped

# APP
  profile_editor2:
    build:
      context: .
      dockerfile: ./Dockerfile
    network_mode: bridge
    container_name: profile_editor2
    volumes:
      - ./image:/app/image
    expose:
      - 8080
    ports:
      - 8080:8080
    restart: unless-stopped
    depends_on:
      - postgres
    links:
      - postgres
volumes:
  postgres-data:

init.sql:-

  create table sometable(id int);   

No table created. I can see only the database is created. How do I create a table and also if possible insert some data into the table?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
masiboo
  • 4,537
  • 9
  • 75
  • 136
  • I run the same compose file and it does show on the logs that only database is created but if you look inside the container you will see that table WAS created, please check like that : `docker-compose exec postgres psql --user postgres dev` and then type `\d` you will see the table. – Batchen Regev Feb 20 '20 at 22:31
  • I tired the same docker-compose exec postgres psql --user postgres dev then \dt or \d Did not find any relations – masiboo Feb 21 '20 at 11:28
  • Does the init.sql is in the same location\dir as the docker.yml file ? i did excetly the same as you. try maybe `docker-compose exec postgres bash` and then look if init file was copied ? – Batchen Regev Feb 24 '20 at 08:39

0 Answers0