mysql5.6.35镜像制作与运行

Dockerfile

FROM centos:7

ENV MYSQL_VERSION="5.6.35"

COPY run.sh  /
COPY init-db.sh /

RUN yum update -y && \
    yum install -y libaio-devel numactl-libs net-tools perl perl-Data-Dumper-Names perl-Data-Dumper perl-DBI  && \
    yum clean all && \
    for  pkg in common libs  devel  client server; \
    do rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql56-community-el7/mysql-community-$pkg-$MYSQL_VERSION-2.el7.x86_64.rpm; done && \
    chmod 755 /run.sh  /init-db.sh  && rm -rf /var/lib/mysql

ENTRYPOINT ["/run.sh"]

run.sh

#! /bin/bash

if [ -z "$@" ]
then
    if [ ! -z "$MYSQL_CONFIG_FILE" ]
    then
        test -f $MYSQL_CONFIG_FILE && cp -fv $MYSQL_CONFIG_FILE /etc/my.cnf
    fi

    d="/var/lib/mysql/mysql"

    test -d "$d" && chown -R mysql:mysql $(dirname $d) || /init-db.sh
    mysqld --user=mysql
else
    "$@"
fi

init-db.sh

#! /bin/bash

m_p="KKxxmt2"

dbdir="/var/lib/mysql"

test -d "$dbdir/mysql" || mysql_install_db
chown -R mysql:mysql $dbdir

echo "Start MySQL Server"
su -mysql -s /bin/bash -c "mysqld &"

echo "Wait 5 seconds for MySQL start"
sleep 5

echo "Set password for root(default is: $m_p)"
mysqladmin -u root password $m_p

echo "Update privilege for root"
mysql -uroot -p$m_p -e "grant all on *.* to root@'%' identified by '$m_p' with grant option;"

# Stop MySQL Server & Start MySQL Server
pid= `ps aux | grep "[m]ysql" | awk '{print $2}'`
kill -9 $pid

docker build -t mysql:5.6.35 .

docker images

docker run ...

docker ps -a

猜你喜欢

转载自www.cnblogs.com/Cohen/p/9032268.html