前提・実現したいこと
dockerの勉強中です。
dockerでDBを作成したくいろいろ試してる途中(DB構築時にテーブルやデータを入れる練習中)なのですが、イメージを再構築してコンテナを起動してもDBの中身が残ったままです。
どうすれば新規に作成できるでしょうか?
なにか手順が足りないでしょうか?
試したこと
コンテナを停止、削除してからvolumeを削除
docker stop container_name docker rm -v container_name docker volume rm vol_data
イメージを再構築してコンテナを起動
docker-compose up -d --build
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
補足情報(FW/ツールのバージョンなど)
macOS

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