LoginSignup
0
1

More than 1 year has passed since last update.

docker-composeでコンテナ生成時にMYSQLにテーブルを追加

Posted at

引用記事

docker-compose.yaml
version: '3'
services:
  app:
    build: ./docker
    ports:
      - 80:80
    volumes:
      - ./app:/var/www/app
    working_dir: /var/www/app
  db:
    image: mysql:8.0
    volumes:
      - ./initdb.d:/docker-entrypoint-initdb.d # コンテナ作成時に実行されるsqlファイルを格納するパスをdocker-entrypoint-initdb.dにマウント
    command: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci
    restart: always
    ports:
      - 3306:3306
    environment:
      MYSQL_DATABASE: image_database
      MYSQL_USER: user
      MYSQL_PASSWORD: pass
      MYSQL_ROOT_PASSWORD: pass

Docker側にマウントしたinitdb.dディレクトリ直下のcreate_table.sqlがコンテナ生成時に実行される。
.sqlのほか、.shも自動的に実行される

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1