当由docker compose启动时如何创建表postgresql(给出的答案不起作用)

时间:2020-02-20 18:12:59

标签: postgresql docker docker-compose

我知道这个问题已经here被问到并且也给出了答案。但这对我不起作用。我也一样我的postgres容器运行正常。我在容器内部检查了/docker-entrypoint-initdb.d/init.sql是否存在。我使用了以下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);   

未创建表。我只能看到数据库已创建。如何创建表,并在可能的情况下将一些数据插入表中?

0 个答案:

没有答案