D
D
DieZz2018-03-25 16:38:37
MySQL
DieZz, 2018-03-25 16:38:37

How to create database from dump during container build?

Good day.
I ran into a problem that I can not create a database and import data from the dump into it.
Here is the Dockerfile

FROM mysql:5.7

ARG MYSQL_DATABASE
ARG MYSQL_USER
ARG MYSQL_PASSWORD
ARG MYSQL_ROOT_PASSWORD

# Create Database
RUN	mkdir /usr/sql
RUN	chmod 644 /usr/sql

COPY dump.sql /usr/sql/dump.sql

COPY mysql.cnf /etc/mysql/conf.d/mysql.cnf

#Create database
RUN /etc/init.d/mysql start && \
    sleep 5 && \
    mysql -u root -p${MYSQL_ROOT_PASSWORD} -e "CREATE DATABASE ${MYSQL_DATABASE}" && \
    mysql -u root -p${MYSQL_ROOT_PASSWORD} -e "CREATE USER '${MYSQL_USER}'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}'" && \
    mysql -u root -p${MYSQL_ROOT_PASSWORD} -e "GRANT ALL PRIVILEGES ON * . * TO '${MYSQL_USER}'@'localhost';" && \
    mysql -u root -p${MYSQL_ROOT_PASSWORD} -e "FLUSH PRIVILEGES" && \
    mysql -u root -p${MYSQL_ROOT_PASSWORD} ${MYSQL_DATABASE} <  /usr/sql/dump.sql

The base is created but it is empty, i.e. There are no tables or data. If then using exec to add a dump, then everything works. Tell me what could be the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question