前提・実現したいこと
dockerでpostgresのコンテナを作成したときにDBやテーブルの作成や、初期データの挿入などをしたいです。
試したこと
Dockerでpostgres構築 初期データも流しますを参考に以下のファイルを作成して
docker-compose up -d --build
でコンテナを作成しました。
該当のソースコード
ディレクトリ構成
|-docker-compose.yml |-docker |-db |-init |-1_createdb.sql |-2_createtable.sh |-web
docker-compose.yml
version: "3" services: web: build: $PWD/docker/web # Specifying the file to build image: webapi # Image name container_name: web-container # Container name ports: # Port on the left to access,right side is the port inside the container - "3000:3000" environment: # Container internal environment variable - "DATABASE_HOST=db" - "DATABASE_PORT=5432" - "DATABASE_USER=postgres" - "DATABASE_PASSWORD=mysecretpassword1234" - "PGPASSWORD=mysecretpassword1234" - "DATABASE_NAME=testdb" links: - db stdin_open: true tty: true entrypoint: ash /app/run.sh java -jar /app/test.jar # command: ash # for debug db: image: postgres:10.6-alpine # Base image file container_name: db-container # Container name ports: # Port on the left to access,right side is the port inside the container - "5432:5432" environment: # Container internal environment variable - "POSTGRES_USER=postgres" - "POSTGRES_PASSWORD=mysecretpassword1234" - "POSTGRES_DB=testdb" volumes: - $PWD/docker/db/init:/docker-entrypoint-initdb.d # Initial data create #- dbdata:/var/lib/postgresql/data # mount postgresql volume volumes: dbdata: driver_opts: type: none device: $PWD/.dbdata # Create volume for postgresql o: bind
1_createdb.sql
create database testdb
2_createtable.sh
psql - U postgres create table public.testtable( user text not null, pw text not null ) with ( OIDS = FALSE );
発生している問題・エラーメッセージ
上記でコンテナを立ち上げてもtestdbというDBは作成されるのですが、testtableテーブルが作成されません。
なぜでしょうか?

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。