[英]Docker-compose initialize DB
我有一個 docker-compose 文件
version: '3.7'
services:
db:
image: mysql:latest
container_name: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: 12345
volumes:
- ./docker/db:/docker-entrypoint-initdb.d
ports:
- "3306:3306"
和一個 MySQL 腳本來初始化數據庫。
CREATE DATABASE `aaa`;
USE `aaa`;
CREATE TABLE `building` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`start_date` date DEFAULT NULL,
`end_date` date DEFAULT NULL,
`open` tinyint(4) DEFAULT NULL,
`address_type` varchar(30) DEFAULT NULL,
`address_name` varchar(45) DEFAULT NULL,
`address_number` varchar(45) DEFAULT NULL,
`cap` char(5) DEFAULT NULL,
`city` varchar(45) DEFAULT NULL,
`province` varchar(45) DEFAULT NULL,
`state` varchar(45) DEFAULT NULL,
`req_amount` float DEFAULT NULL,
PRIMARY KEY (`id`)
);
實際上 Docker 忽略文件 INIT_DB.SQL 如下所述:
mysql | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/DB_INIT.SQL
我想用那個文件初始化數據庫。 我也試過: tomcat + mysql + war 使用 docker-compose.yml 。
錯在哪里?
這對我有用:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
ports:
- "3306:3306"
environment:
TZ: "America/Halifax"
MYSQL_ROOT_PASSWORD: example
MYSQL_DATABASE: formulary
volumes:
- ./mysql-init.sql:/docker-entrypoint-initdb.d/mysql-init.sql
- ./mysql.cnf:/etc/mysql/conf.d/mysql.cnf
你放的和我放的唯一的區別是我放了源文件/目標文件(不僅僅是目錄)。 另外,您確定 ./docker/db 包含您的文件嗎?
在第一個答案(..是一個目錄)下面的評論中得到了同樣的錯誤。 什么對我有用;
postgres:
volumes:
- ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.