搭建了httpyum仓库
Dockerfile 主要文件 基于centos基础镜像
centos.repo yum仓库
db_init.sh mysql初始化脚本
run.sh 启动脚本
vim Dockerfile写入FROM centosMAINTAINER teacher lyRUN mkdir /etc/yum.repos.d/bak ; mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bakADD centos.repo /etc/yum.repos.d/centos.repoRUN yum clean all ; yum -y install wgetRUN yum -y install mariadb-server mariadb net-toolsENV MARIADB_USER root
ENV MARIADB_PASS 123456
ENV LC_ALL en_US.UTF-8ADD db_init.sh /root/db_init.sh
RUN chmod 775 /root/db_init.sh
RUN /root/db_init.sh
EXPOSE 3306ADD run.sh /root/run.sh
RUN chmod 775 /root/run.shCMD ["/root/run.sh"]
dockerfile文件
vim run.sh写入#!/bin/bash
mysqld_safe
启动脚本
vim centos.repo写入[local]
name=local
baseurl=http://192.168.6.1/yum
enabled=1
gpgcheck=0
yum仓库
db_init.sh写入#!/bin/bashmysql_install_db --user=mysqlsleep 3
mysqld_safe &
sleep 3
#mysqladmin -u "$MARIADB_USER" password "$MARIADB_PASS"
mysql -e "use mysql; grant all privileges on *.* to '$MARIADB_USER'@'%' identified by '$MARIADB_PASS' with grant option;"
h=$(hostname)
mysql -e "use mysql; update user set password=password('$MARIADB_PASS') where user='$MARIADB_USER' and host='$h';"
mysql -e "flush privileges;"
docker build -t mysql:mysql ./
docker run -d -P mysql:mysql
mysql -uroot -h 192.168.6.1 -P 32769 -p123456