Docker — MySQL 8 создание образа с дампом

Пример сборки докер образа MySQL 8 с базой данных, с дамп файла.

Содержимое:

  • Dockerfile
  • mysqld.cnf
  • dump.sql

 

Dockerfile:

FROM mysql:8

RUN apt update && \
    apt install -y psmisc

ENV MYSQL_ROOT_PASSWORD MyRootPassword
ENV MYSQL_DATABASE artem_db
ENV MYSQL_USER database_user
ENV MYSQL_PASSWORD MyUserPassword

COPY dump.sql /docker-entrypoint-initdb.d/db.sql
COPY my.cnf /etc/mysql/my.cnf
RUN /entrypoint.sh mysqld &; sleep 30 && killall mysqld
RUN rm /docker-entrypoint-initdb.d/db.sql

 

Обратите внимание, что теперь переменные "MYSQL_USER" и "MYSQL_PASSWORD" задаются в Dockerfile

 

В файле "my.cnf" необходимо заменить только дефолтный путь хранения файлов MySQL

mysqld.cnf

# 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

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Custom config should go here
!includedir /etc/mysql/conf.d/

 

Путь в этой строке:

datadir		= /var/lib/mysql

На другой путь:

datadir		= /var/lib/mysql_artem_service

 

И собираем образ:

docker build -t artem_db .

Метки: Метки

Подписаться
Уведомить о
guest

0 комментариев
Межтекстовые Отзывы
Посмотреть все комментарии