编写Dockerfile生成项目导入定制化的数据表数据的mysql镜像

初始化数据库的sql文件

# cat lagou.sql

SET NAMES utf8;
DROP DATABASE IF EXISTS lagou;
create database lagou CHARSET=utf8 COLLATE=utf8_general_ci;
use lagou;
DROP TABLE IF EXISTS `tbuser`;
CREATE TABLE `tbuser` 
( `userid` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(20) COLLATE utf8_general_ci DEFAULT NULL, 
`password` varchar(20) COLLATE utf8_general_ci DEFAULT NULL, 
`userroles` varchar(2) COLLATE utf8_general_ci DEFAULT NULL,
`nickname` varchar(50) COLLATE utf8_general_ci DEFAULT NULL,
PRIMARY KEY (`userid`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO tbuser (username,PASSWORD,userroles,nickname) VALUES ('admin','1234','04','管理员'),('lagou','1234','03','拉勾教育');

 

编写Dockerfile

# cat Dockerfile

FROM mysql:5.7.31
MAINTAINER mysql from date UTC by Asia/Shanghai "jack@163.com"
ENV TZ Asia/Shanghai

COPY lagou.sql /docker-entrypoint-initdb.d

编译并推送镜像到仓库

docker build -t 10.9.3.231:5000/lagouedu/mysql:5.7.1 .
docker push 10.9.3.231:5000/lagouedu/mysql:5.7.1

 

运行容器

# docker run -it -d --name mysql01 --restart always -p 3306:3306 --privileged=true -e MYSQL_ROOT_PASSWORD=root -v /data/mysql_data:/var/lib/mysql 10.9.3.231:5000/lagouedu/mysql:5.7.1 --character-set-server=utf8 --collation-server=utf8_general_ci

 

 

posted @ 2021-10-21 13:44  reblue520  阅读(207)  评论(0编辑  收藏  举报