简体   繁体   English

自定义mysql高山映像未从作为卷安装的docker-entrypoint-initdb.d加载init.sql

[英]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.

相关问题 MySql Docker /docker-entrypoint-initdb.d 编码错误 - MySql Docker /docker-entrypoint-initdb.d wrong Encoding docker 权限被拒绝 mysql 映像中的 shell 脚本放置在 docker-entrypoint-initdb.d - docker permission denied for shell script in mysql image placed at docker-entrypoint-initdb.d sql转储是否被加密到docker容器docker-entrypoint-initdb.d中? - Are sql dumps moved into docker container `docker-entrypoint-initdb.d` encrypted? 无法使用 mysql docker 容器在 docker-entrypoint-initdb.d 中创建数据库 - Can't create db in docker-entrypoint-initdb.d with mysql docker container 当容器从另一个容器中启动时,docker-entrypoint-initdb.d 为空 - docker-entrypoint-initdb.d is empty when container is started from within another container 命令&#39;/ bin / sh -c mysql -u wordpress -pwordpress wordpress &lt;/docker-entrypoint-initdb.d/wordpress.sql&#39;返回非零代码:1 - The command '/bin/sh -c mysql -u wordpress -pwordpress wordpress < /docker-entrypoint-initdb.d/wordpress.sql' returned a non-zero code: 1 为什么我的 docker-entrypoint-initdb.d 脚本(在 docker-compose.yml 中指定)没有被执行来初始化一个新的 MySQL 实例? - Why isn't my docker-entrypoint-initdb.d script (as specified in docker-compose.yml) executed to initialize a fresh MySQL instance? docker-compose up invalid mode /docker-entrypoint-initdb.d/ - 无法为服务数据库创建容器 - docker-compose up invalid mode /docker-entrypoint-initdb.d/ - cannot create container for service database 如何等待docker-entrypoint-initdb.d在Shell脚本/ Bash中加载数据库? - How to wait for docker-entrypoint-initdb.d to load DB in Shell Script/Bash? docker-entrypoint-initdb 中的 MySQL 脚本不执行 - MySQL scripts in docker-entrypoint-initdb are not executed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM