Modifying Dockerfile
- Go to the directory where the Dockerfile file is stored.
1cd mysql-docker/8.0
- Ensure that you have permissions to execute docker-entrypoint.sh and healthcheck.sh.
1chmod 755 ./docker-entrypoint.sh ./healthcheck.sh
- Modify the MySQL 8.0.19 Dockerfile.
1vim Dockerfile - The original content of Dockerfile is as follows:
# 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"]Press i to enter the insert mode and modify the file as follows:
# 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"]
Description of the modifications:
- The system image is changed from oraclelinux:7-slim to centos:centos8.2.2004.
- In the source version, the MySQL package is downloaded from the remote Yum source for installation. In this version, the MySQL installation file is copied from the physical machine and then installed from the local server.
- The --user=root parameter is added to the CMD startup parameter to ensure that the CentOS system in the Docker container can start the mysqld process as the root user.
If the network environment where the physical machine is located cannot directly access the Internet, add the proxy configuration to the Dockerfile file. Add the ENV configuration proxy information after FROM, and clear the proxy information before CMD. The following is an example:
... FROM centos:centos8.2.2004 ENV http_proxy="http://proxy service username:proxy service password@proxy service IP address:proxy service port" 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"]
- Press Esc, type :wq!, and press Enter to save the file and exit.
Parent topic: Constructing a MySQL Docker Image