构建MySQL8.0镜像
Posted _雪辉_
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了构建MySQL8.0镜像相关的知识,希望对你有一定的参考价值。
一、准备mysql官方dockerfile
git clone https://github.com/mysql/mysql-docker.git
二、准备官方包
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.26-el7-x86_64.tar
tar xf mysql-8.0.26-el7-x86_64.tar -C mysql-docker/mysql-server/8.0/
cd mysql-docker/mysql-server/8.0
tar xf mysql-8.0.26-el7-x86_64.tar.gz
tar xf mysql-test-8.0.26-el7-x86_64.tar.gz
三、修改dockerfile
cd mysql-docker/mysql-server/8.0
chmod 755 ./docker-entrypoint.sh ./healthcheck.sh
echo '''# Copyright (c) 2017, 2021, Oracle and/or its affiliates.
#
# 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.26
ARG MYSQL_SHELL_PACKAGE=mysql-shell-8.0.26
COPY mysql-community-client-8.0.26-1.el7.x86_64.rpm ./mysql-community-client-8.0.26-1.el7.x86_64.rpm
COPY mysql-community-client-plugins-8.0.26-1.el7.x86_64.rpm ./mysql-community-client-plugins-8.0.26-1.el7.x86_64.rpm
COPY mysql-community-common-8.0.26-1.el7.x86_64.rpm ./mysql-community-common-8.0.26-1.el7.x86_64.rpm
COPY mysql-community-devel-8.0.26-1.el7.x86_64.rpm ./mysql-community-devel-8.0.26-1.el7.x86_64.rpm
COPY mysql-community-embedded-compat-8.0.26-1.el7.x86_64.rpm ./mysql-community-embedded-compat-8.0.26-1.el7.x86_64.rpm
COPY mysql-community-libs-8.0.26-1.el7.x86_64.rpm ./mysql-community-libs-8.0.26-1.el7.x86_64.rpm
COPY mysql-community-libs-compat-8.0.26-1.el7.x86_64.rpm ./mysql-community-libs-compat-8.0.26-1.el7.x86_64.rpm
COPY mysql-community-server-8.0.26-1.el7.x86_64.rpm ./mysql-community-server-8.0.26-1.el7.x86_64.rpm
COPY mysql-community-test-8.0.26-1.el7.x86_64.rpm ./mysql-community-test-8.0.26-1.el7.x86_64.rpm
# Setup repositories for minimal packages (all versions)
#RUN rpm -U https://repo.mysql.com/mysql-community-minimal-release-el8.rpm \\
# && rpm -U https://repo.mysql.com/mysql80-community-release-el8.rpm
# Install server and shell 8.0
#RUN microdnf update && echo "[main]" > /etc/dnf/dnf.conf \\
# && microdnf install -y $MYSQL_SHELL_PACKAGE \\
# && microdnf install -y --disablerepo=ol8_appstream \\
# --enablerepo=mysql80-server-minimal $MYSQL_SERVER_PACKAGE \\
# && microdnf clean all \\
# && mkdir /docker-entrypoint-initdb.d
RUN yum localinstall -y mysql-community-* \\
&& yum clean all \\
&& mkdir /docker-entrypoint-initdb.d
VOLUME /data/mysql8/mysql
RUN rm ./mysql-community-*
#COPY prepare-image.sh /
#RUN /prepare-image.sh && rm -f /prepare-image.sh
#ENV MYSQL_UNIX_PORT /var/lib/mysql/mysql.sock
COPY docker-entrypoint.sh /entrypoint.sh
COPY healthcheck.sh /healthcheck.sh
ENTRYPOINT ["/entrypoint.sh"]
HEALTHCHECK CMD /healthcheck.sh
EXPOSE 3306 33060 33061
CMD ["mysqld","--user=root"]
'''
>> Dockerfile
四、构建镜像
docker build -t mysql/centos7-mysql-x86:8.0.26 .
Sending build context to Docker daemon 808.3 MB
Step 1/21 : FROM oraclelinux:7-slim
---> 02b527a2b956
Step 2/21 : ARG MYSQL_SERVER_PACKAGE=mysql-community-server-minimal-8.0.26
---> Using cache
---> 67b0422c1d46
Step 3/21 : ARG MYSQL_SHELL_PACKAGE=mysql-shell-8.0.26
---> Using cache
---> d386febe5296
Step 4/21 : COPY mysql-community-client-8.0.26-1.el7.x86_64.rpm ./mysql-community-client-8.0.26-1.el7.x86_64.rpm
---> Using cache
---> 9649a7dc43ef
Step 5/21 : COPY mysql-community-client-plugins-8.0.26-1.el7.x86_64.rpm ./mysql-community-client-plugins-8.0.26-1.el7.x86_64.rpm
---> Using cache
---> 508bf926a8a6
Step 6/21 : COPY mysql-community-common-8.0.26-1.el7.x86_64.rpm ./mysql-community-common-8.0.26-1.el7.x86_64.rpm
---> Using cache
---> a1441d4cadb3
Step 7/21 : COPY mysql-community-devel-8.0.26-1.el7.x86_64.rpm ./mysql-community-devel-8.0.26-1.el7.x86_64.rpm
---> Using cache
---> 664a0b3e9c88
Step 8/21 : COPY mysql-community-embedded-compat-8.0.26-1.el7.x86_64.rpm ./mysql-community-embedded-compat-8.0.26-1.el7.x86_64.rpm
---> Using cache
---> fc808591a57e
Step 9/21 : COPY mysql-community-libs-8.0.26-1.el7.x86_64.rpm ./mysql-community-libs-8.0.26-1.el7.x86_64.rpm
---> Using cache
---> e3b560e196bb
Step 10/21 : COPY mysql-community-libs-compat-8.0.26-1.el7.x86_64.rpm ./mysql-community-libs-compat-8.0.26-1.el7.x86_64.rpm
---> Using cache
---> 41a0a2ba993a
Step 11/21 : COPY mysql-community-server-8.0.26-1.el7.x86_64.rpm ./mysql-community-server-8.0.26-1.el7.x86_64.rpm
---> Using cache
---> 40b603588918
Step 12/21 : COPY mysql-community-test-8.0.26-1.el7.x86_64.rpm ./mysql-community-test-8.0.26-1.el7.x86_64.rpm
---> Using cache
---> c31877c6c640
Step 13/21 : RUN yum localinstall -y mysql-community-* && yum clean all && mkdir /docker-entrypoint-initdb.d
---> Using cache
---> 691c5313f059
Step 14/21 : VOLUME /data/mysql8/mysql
---> Using cache
---> 2eb2318d20f5
Step 15/21 : RUN rm ./mysql-community-*
---> Using cache
---> 441567030980
Step 16/21 : COPY docker-entrypoint.sh /entrypoint.sh
---> Using cache
---> e4dd4a18dc92
Step 17/21 : COPY healthcheck.sh /healthcheck.sh
---> Using cache
---> a6a5330b9cf0
Step 18/21 : ENTRYPOINT /entrypoint.sh
---> Using cache
---> e765e55c5f37
Step 19/21 : HEALTHCHECK CMD /healthcheck.sh
---> Using cache
---> e17b584e7821
Step 20/21 : EXPOSE 3306 33060 33061
---> Using cache
---> 3b997176f011
Step 21/21 : CMD mysqld --user=root
---> Using cache
---> 4e4c5ebc88e2
Successfully built 4e4c5ebc88e2
五、导出镜像
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql/centos7-mysql-x86 8.0.26 4e4c5ebc88e2 2 hours ago 4.45 GB
docker save -o /root/mysql-docker/mysql-server/8.0/mysql_centos8-mysql-x86_8.0.26.tar mysql/centos7-mysql-x86:8.0.26
以上是关于构建MySQL8.0镜像的主要内容,如果未能解决你的问题,请参考以下文章