在docker容器构建时解压缩mysql转储

时间:2018-03-25 14:02:05

标签: mysql docker

我尝试在docker容器构建时提取mysql转储,但我得到一个空表。这是我的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

当容器准备就绪时,我有一个空数据库(没有表和数据)

0 个答案:

没有答案