搭建了httpyum仓库
Dockerfile 主要文件 基于centos基础镜像
centos.repo yum仓库
db_init.sh mysql初始化脚本
run.sh 启动脚本
vim Dockerfile
写入
FROM centos
MAINTAINER teacher ly
RUN mkdir /etc/yum.repos.d/bak ; mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
ADD centos.repo /etc/yum.repos.d/centos.repo
RUN yum clean all ; yum -y install wget
RUN yum -y install mariadb-server mariadb net-tools
ENV MARIADB_USER root
ENV MARIADB_PASS 123456
ENV LC_ALL en_US.UTF-8
ADD db_init.sh /root/db_init.sh
RUN chmod 775 /root/db_init.sh
RUN /root/db_init.sh
EXPOSE 3306
ADD run.sh /root/run.sh
RUN chmod 775 /root/run.sh
CMD ["/root/run.sh"]
dockerfile文件
vim run.sh
写入
#!/bin/bash
mysqld_safe
启动脚本
vim centos.repo
写入
[local]
name=local
baseurl
enabled=1
gpgcheck=0
yum仓库
db_init.sh
写入
#!/bin/bash
mysql_install_db --user=mysql
sleep 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