【MySQL】用MySQL8.x二进制包构建MySQL镜像

#  mkdir /root/mysql8.0.18-docker 

#  cd  /root/mysql8.0.18-docker

 

# wget  -O   gosu  https://github.com/tianon/gosu/releases/download/1.7/gosu-amd64

# chmod  +x  gosu

 

#  wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz  

#  tar  -Jxf  mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz

#  mv   mysql-8.0.18-linux-glibc2.12-x86_64   mysql

# tar -zcf  mysql-8.0.18-bin.tar.gz   mysql

 

【MySQL】用MySQL8.x二进制包构建MySQL镜像_第1张图片

 

# cat  Dockerfile

################################################################

FROM centos:centos7.5.1804

ADD  mysql-8.0.18-bin.tar.gz /usr/local

RUN echo "sslverify=0" >> /etc/yum.conf && \

    yum clean all && \

    rpm --rebuilddb && \

    yum -y install net-tools libaio perl numactl && \

    groupadd -g 2020 mysql && \

    useradd -r -u 2020 -g  mysql -s /sbin/nologin mysql && \

    mkdir -p /var/lib/mysql /etc/mysql/conf.d && \

    mkdir -p /var/run/mysqld /opt/mysql/sec_file && \

    chown -R mysql:mysql /usr/local/mysql /var/lib/mysql /etc/mysql /var/run/mysqld /opt/mysql/sec_file

COPY docker-entrypoint.sh  /

COPY my.cnf  /etc/mysql

COPY gosu /usr/local/bin/

RUN chown -R mysql:mysql /etc/mysql /docker-entrypoint.sh && \

    chmod 700 /docker-entrypoint.sh /usr/local/bin/gosu && \

    chmod 600 /etc/mysql/my.cnf

VOLUME /var/lib/mysql

ENV  PATH=/usr/local/mysql/bin:$PATH

ENV  MYSQL_HISTFILE=/dev/null

ENTRYPOINT ["/docker-entrypoint.sh"]

EXPOSE 3306 33060

CMD ["mysqld"]

################################################################

【MySQL】用MySQL8.x二进制包构建MySQL镜像_第2张图片

 

# cat docker-entrypoint.sh

############################################################

#!/bin/sh

set -e

umask 0077

if [ -z "$(ls -A /var/lib/mysql)" ]; then

    if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then

        mysqld --initialize-insecure --user=mysql

    else

        mysqld --initialize-insecure --user=mysql

        cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

        chmod +x /etc/init.d/mysqld

        /etc/init.d/mysqld start

        mysql -u root --skip-password -e "alter user root@'localhost' identified by \"${MYSQL_ROOT_PASSWORD}\";"

        mysql -u root  -p"${MYSQL_ROOT_PASSWORD}" -e "flush privileges;"

        /etc/init.d/mysqld stop

        rm -f /etc/init.d/mysqld

    fi

fi

exec gosu mysql "$@"

############################################################

【MySQL】用MySQL8.x二进制包构建MySQL镜像_第3张图片

# chmod +x   docker-entrypoint.sh

在MySQL数据目录为空、允许以非安全模式(root@'localhost'为空密码)初始化:

1. 如果MYSQL_ROOT_PASSWORD为空值,直接以非安全模式(root空密码)初始化

2. 如果MYSQL_ROOT_PASSWORD不为空值,以非安全模式初始化,然后根据MYSQL_ROOT_PASSWORD的传值,设置root@'localhost'的密码

# cat my.cnf

################################################################

[mysqld]

pid-file                            = /var/run/mysqld/mysqld.pid

socket                             = /tmp/mysql.sock

datadir                             = /var/lib/mysql

secure-file-priv                = /opt/mysql/sec_file

symbolic-links                  = 0

max_connections             = 1000

user                                  = mysql

skip_name_resolve

skip-host-cache

skip-log-bin

character-set-client-handshake  = FALSE

lower_case_table_names          = 1

sql-mode                        = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"

character-set-server            = utf8

collation-server                = utf8_general_ci

init_connect                    = "SET NAMES 'utf8'"

default_authentication_plugin    = mysql_native_password

[mysql]

default-character-set            = utf8

[client]

default-character-set            = utf8

###################################################################

【MySQL】用MySQL8.x二进制包构建MySQL镜像_第4张图片

 

#  docker  build  -f  Dockerfile  -t  mysql:8.0.18  .

【MySQL】用MySQL8.x二进制包构建MySQL镜像_第5张图片

看到这个大小,只能说......看看就好!

 

 

【MySQL&docker】基于CentOS7.5 编译制作MySQL5.7.28镜像

https://www.jianshu.com/p/71fd79b69a6b

 

【MySQL&docker】基于CentOS7.5 编译制作MySQL5.7.28安全加固镜像

https://www.jianshu.com/p/7de9b74c6a5b

你可能感兴趣的:(docker,MySQL,Linux)