---
title: 修改Dockerfile
description: "1. 进入Dockerfile所在目录。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengdbs/ecosystemEnable/MySQL/kunpengmysqlmgr_03_0016.html
sourcePath: /source/zh/kunpengdbs/ecosystemEnable/MySQL/kunpengmysqlmgr_03_0016.html
indexId: dbb7f8579b887b63f358f398bf85c6f3b52de3e94503c07f51bc5d91834f509272
---
# 修改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原始内容如下：
```
# 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”进入编辑模式，修改后内容：
```
# 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"]
```

修改内容说明：

  a. 将原先使用的系统镜像由oraclelinux:7-slim改为centos:centos8.2.2004。
  b. 将原先使用从远程yum源下载MySQL包安装，改为从物理机复制MySQL安装文件，再从本地文件安装。
  c. CMD启动参数增加“--user=root”参数，保证Docker容器中CentOS系统可以使用root用户启动mysqld。
如果物理机所在网络环境无法直接访问外网，可在Dockerfile中增加代理配置，在添加FROM之后添加ENV配置代理信息，在CMD之前清除代理信息，修改示例如下：

```
 
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”保存并退出编辑。
