修改Dockerfile

  1. 进入Dockerfile所在目录。

    1
    cd mysql-docker/8.0
    

  2. 确保docker-entrypoint.sh和healthcheck.sh具有可执行权限。

    1
    chmod 755 ./docker-entrypoint.sh ./healthcheck.sh
    

  3. 修改MySQL 8.0.19 Dockerfile。

    1
    vim Dockerfile
    

  4. Dockerfile原始内容如下:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    # Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
    #
    # This program is free software; you can redistribute it and/or modify
    # it under the terms of the GNU General Public License as published by
    # the Free Software Foundation; version 2 of the License.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program; if not, write to the Free Software
    # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
    FROM oraclelinux:7-slim
     
    ARG MYSQL_SERVER_PACKAGE=mysql-community-server-minimal-8.0.20
    ARG MYSQL_SHELL_PACKAGE=mysql-shell-8.0.20
     
    # Install server
    RUN yum install -y https://repo.mysql.com/mysql-community-minimal-release-el7.rpm \
          https://repo.mysql.com/mysql-community-release-el7.rpm \
      && yum-config-manager --enable mysql80-server-minimal \
      && yum install -y \
          $MYSQL_SERVER_PACKAGE \
          $MYSQL_SHELL_PACKAGE \
          libpwquality \
      && yum clean all \
      && mkdir /docker-entrypoint-initdb.d
     
    VOLUME /var/lib/mysql
     
    COPY docker-entrypoint.sh /entrypoint.sh
    COPY healthcheck.sh /healthcheck.sh
    ENTRYPOINT ["/entrypoint.sh"]
    HEALTHCHECK CMD /healthcheck.sh
    EXPOSE 3306 33060
    CMD ["mysqld"]
    

    “i”进入编辑模式,修改后内容

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    # Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
    #
    # This program is free software; you can redistribute it and/or modify
    # it under the terms of the GNU General Public License as published by
    # the Free Software Foundation; version 2 of the License.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program; if not, write to the Free Software
    # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
    FROM centos:centos8.2.2004
    
    ARG MYSQL_SERVER_PACKAGE=mysql-community-server-minimal-8.0.19
    ARG MYSQL_SHELL_PACKAGE=mysql-shell-8.0.19
     
    COPY mysql-community-common-8.0.19-1.el8.aarch64.rpm ./mysql-community-common-8.0.19-1.el8.aarch64.rpm
    COPY mysql-community-libs-8.0.19-1.el8.aarch64.rpm ./mysql-community-libs-8.0.19-1.el8.aarch64.rpm
    COPY mysql-community-client-8.0.19-1.el8.aarch64.rpm ./mysql-community-client-8.0.19-1.el8.aarch64.rpm
    COPY mysql-community-server-8.0.19-1.el8.aarch64.rpm ./mysql-community-server-8.0.19-1.el8.aarch64.rpm
     
    # Install server
    RUN yum localinstall -y mysql-community-* \
      && yum clean all \
      && mkdir /docker-entrypoint-initdb.d
     
    VOLUME /var/lib/mysql
     
    RUN rm ./mysql-community-*
     
    COPY docker-entrypoint.sh /entrypoint.sh
    COPY healthcheck.sh /healthcheck.sh
    ENTRYPOINT ["/entrypoint.sh"]
    HEALTHCHECK CMD /healthcheck.sh
    EXPOSE 3306 33060
    CMD ["mysqld", "--user=root"]
    

    修改内容说明:

    1. 将原先使用的系统镜像由oraclelinux:7-slim改为centos:centos8.2.2004。
    2. 将原先使用从远程yum源下载MySQL包安装,改为从物理机复制MySQL安装文件,再从本地文件安装。
    3. CMD启动参数增加“--user=root”参数,保证Docker容器中CentOS系统可以使用root用户启动mysqld。

    如果物理机所在网络环境无法直接访问外网,可在Dockerfile中增加代理配置,在添加FROM之后添加ENV配置代理信息,在CMD之前清除代理信息,修改示例如下:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    ...
     
    FROM centos:centos8.2.2004
     
    ENV http_proxy="http://代理服务用户名:代理服务密码@代理服务IP地址:代理服务端口"
    ENV https_proxy=$http_proxy
    ENV no_proxy=127.0.0.1,localhost,local,.local
     
    ...
     
    ENV http_proxy=""
    ENV https_proxy=""
    ENV no_proxy=""
     
    CMD ["mysqld", "--user=root"]
    

  5. Dockerfile修改完成后,按“Esc”键,输入:wq!,按“Enter”保存并退出编辑。