[英]Custom mysql alpine image not loading init.sql from docker-entrypoint-initdb.d mounted as a volume
I am trying to create a customer mysql image from base image as alpine. 我正在尝试从基本映像(如高山)创建客户mysql映像。 I have installed the necessary packages for mysql via apk through dockerfile.
我已经通过dockerfile通过apk安装了mysql所需的软件包。 My requirement is i want to run a fresh instance of mysql_alpine and create and modify tables in the db.
我的要求是我想运行mysql_alpine的新实例并在数据库中创建和修改表。 My data files are located in /var/lib/mysql/ mounted as a volume and my init.sql is mounted as a volume into /docker-entrypoint-initdb.d/.
我的数据文件作为卷安装在/ var / lib / mysql /中,而我的init.sql作为卷安装在/docker-entrypoint-initdb.d/中。 Following is my dockerfile
以下是我的dockerfile
FROM alpine
RUN apk update && \
apk --no-cache add mysql mysql-client && \
addgroup mysql mysql && \
mkdir docker-entrypoint-initdb.d && \
mkdir run/mysqld && \
chown -R mysql:mysql /run/mysqld && \
chown -R mysql:mysql /docker-entrypoint-initdb.d && \
chown -R mysql:mysql /var/lib/mysql && \
chmod -R +x /docker-entrypoint-initdb.d/ && \
mysql_install_db --user=mysql
ENV "MYSQL_ROOT_PASSWORD= " \
"MYSQL_DATABASE=mysql" \
"MYSQL_USER=test" \
"MYSQL_PASSWORD=mypassword"
VOLUME ~/mysql/init/:/docker-entrypoint-initdb.d/ && \
~/mysql/db/:/var/lib/mysql/
CMD /usr/bin/mysqld --user=mysql
After i build the container when i run the conatiner with the command: 当我使用以下命令运行conatiner时,构建容器之后:
docker run -d -p 3307:3306 --name mysql_alpine mysql_alpine
only the db starts but there is no init.sql file inside docker-entrypoint-intidb.d/ folder and so, the file never got loaded when initializing the db 仅数据库启动,但docker-entrypoint-intidb.d /文件夹中没有init.sql文件,因此,初始化数据库时从未加载该文件
My init.sql file which is not getting mounted into docker-entrypoint-initdb.d folder inside the container: 我的init.sql文件没有安装到容器内的docker-entrypoint-initdb.d文件夹中:
CREATE DATABASE IF NOT EXISTS mysql;
USE mysql;
CREATE USER 'test'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL ON my_db.* TO 'testdata'@'localhost';
FLUSH PRIVILEGES;
First of all, you need to fix your volume section, as : 首先,您需要修复音量部分,例如:
VOLUME ~/mysql/init/:/docker-entrypoint-initdb.d/ && \
~/mysql/db/:/var/lib/mysql/
is not correct, check the documentation , instead you should use COPY
instead: 不正确,请检查文档 ,而应改用
COPY
:
COPY mysql/init/ /docker-entrypoint-initdb.d/
COPY mysql/db/ /var/lib/mysql/
And you need to make sure that mysql
directory is on the same level as your Dockerfile
. 并且您需要确保
mysql
目录与Dockerfile
位于同一级别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.