目標
- 為了讓每次測試更加快速的建立 db 中的資料環境,分開 schema.sql & init_value.sql 兩個檔案,方便修改
- 步驟
- 透過 docker-compose 建立 container:mariadb
- 透過 volume 的方式,掛載 base_schema.sql & init_value.sql 檔案
- 建立的過程中,讓 container:mariadb 自行初始化 (2) 的檔案
docker
- hub :
https://hub.docker.com/_/mariadb/
Initializing a fresh instance
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. You can easily populate your mariadb services by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by the MYSQL_DATABASE variable.
測試
- sqlfile 檔案名稱,不能用數字代替英文字母
- 所有的檔案要放在 container 中的
/docker-entrypoint-initdb.d
位置
sql file
- schema
1 |
|
- init value
1 |
|
docker-compose
1 |
|