不执行docker-compose mariadb docker-entrypoint-initdb.d sql [英] docker-compose mariadb docker-entrypoint-initdb.d sql is not executed

查看:133
本文介绍了不执行docker-compose mariadb docker-entrypoint-initdb.d sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的docker db容器在创建时自动使用数据集填充数据库.根据 mariadb文档,有一个 docker-entrypoint-initdb.d 可以用于此目的的卷中的文件夹.

I am attempting to have my docker db container automatically populate the database with a dataset when created. According to the mariadb documentation, there is an docker-entrypoint-initdb.d folder in the volume that can be used for this purpose.

我设置了 docker-compose.yml 文件,以镜像在StackOverflow上找到的示例,但是仍然无法使我的SQL脚本执行.这是我的 docker-compose.yml 文件的相关部分:

I set up my docker-compose.yml file to mirror examples that I have found on StackOverflow, but am still unable to get my SQL scripts to execute. Here are the relevant pieces of my docker-compose.yml file:

version: '3.6'
services:

  db:
    image: mariadb:10.5.4-focal
    container_name: db
    volumes:
      - ./cms/conf/mysql/data/:/var/lib/mysql/:rw
      - ./cms/sql/:/docker-entrypoint-initdb.d/:ro
    environment:
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_USER=root
      - MYSQL_PASSWORD=password
      - MYSQL_DATABASE=wordpress
    restart: always

  adminer:
    image: adminer:4.7.7-standalone
    container_name: adminer
    links:
      - db
    ports:
      - 8080:8080
    restart: always

docker-compose.yml 文件旁边,我有一个 cms/sql/init.sql 文件,内容如下:

Next to the docker-compose.yml file, I have a cms/sql/init.sql file with the following contents:

CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
USE `test`;

在每次测试迭代之前,我会清理所有旧的/缓存的 Docker 内容:

Prior to each test iteration, I clean up any old/cached Docker content:

  1. $ docker-compose down -v 我发现这实际上并没有删除数据库卷.运行 docker volume ls 仍显示过去的卷.
  2. $ docker volume prune 这将清除卷.在运行 docker volume ls 之后,将显示一个空列表.
  3. $ rm -rf ./cms/conf/mysql 这将清除db容器所做的任何实际文件系统更改.
  4. $ docker-compose up -d --build 重建容器.这应该会触发我的初始化SQL脚本.
  1. $ docker-compose down -v I've found this doesn't actually remove the db volumes. Running a docker volume ls still shows past volumes present.
  2. $ docker volume prune This clears out the volumes. Running docker volume ls after running this shows an empty list.
  3. $ rm -rf ./cms/conf/mysql This cleans out any actual filesystem changes that the db container made.
  4. $ docker-compose up -d --build To rebuild the containers. This should trigger my initialization SQL scripts.

Docker运行,并且成功创建了 db 容器.我可以访问在 localhost:8080 上运行的 adminer 容器.我可以使用 docker-compose.yml 文件中指定的密码作为 root 用户登录.

Docker runs, and the db container gets successfully created. I am able to access the adminer container running on localhost:8080. I am able to log in as the root user with the password specified in the docker-compose.yml file.

Adminer 界面显示了标准的 MySQL 数据库(information_schemamysqlperformance_schema)并另外显示了 wordpress docker-compose.yml 文件的 MYSQL_DATABASE 值中定义的数据库.但是我找不到 init.sql 中的 test 数据库.

The Adminer interface shows the standard MySQL databases (information_schema, mysql, performance_schema) and additionally shows the wordpress database defined in the MYSQL_DATABASE value of the docker-compose.yml file. But my test database from the init.sql is nowhere to be found.

我发现了其他一些具有类似问题的类似StackOverflow问题.我已经遵循了可接受的答案,但是仍然无法获取任何SQL脚本来执行.

I found some other similar StackOverflow questions that have had similar problems. I've followed the accepted answers, and am still unable to get any SQL scripts to get executed.

  1. 与Docker有关的问题一次构成了初始数据库设置
  2. mySQL初始化脚本未与docker-compose一起运行
  3. 在docker-compose启动上创建数据库

这是我的 db 容器中的Docker日志.我没有看到任何看起来很奇怪的东西.没有有关初始化等的错误消息:

Here's the Docker log from my db container. I didn't see anything that looked strange; no error messages about initialization, etc:

2020-07-15 19:21:34+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.4+maria~focal started.

2020-07-15 19:21:35+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'

2020-07-15 19:21:35+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.4+maria~focal started.

2020-07-15 19:21:35+00:00 [Note] [Entrypoint]: Initializing database files



PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !

To do so, start the server, then issue the following commands:


'/usr/bin/mysqladmin' -u root password 'new-password'

'/usr/bin/mysqladmin' -u root -h password 'new-password'


Alternatively you can run:

'/usr/bin/mysql_secure_installation'


which will also give you the option of removing the test

databases and anonymous user created by default. This is

strongly recommended for production servers.


See the MariaDB Knowledgebase at https://mariadb.com/kb or the

MySQL manual for more instructions.


Please report any problems at https://mariadb.org/jira


The latest information about MariaDB is available at https://mariadb.org/.

You can find additional information about the MySQL part at:

https://dev.mysql.com

Consider joining MariaDB's strong and vibrant community:

https://mariadb.org/get-involved/


2020-07-15 19:21:47+00:00 [Note] [Entrypoint]: Database files initialized

2020-07-15 19:21:47+00:00 [Note] [Entrypoint]: Starting temporary server

2020-07-15 19:21:47+00:00 [Note] [Entrypoint]: Waiting for server startup

2020-07-15 19:21:47 0 [Note] mysqld (mysqld 10.5.4-MariaDB-1:10.5.4+maria~focal) starting as process 107 ...

2020-07-15 19:21:47 0 [Note] InnoDB: Using Linux native AIO

2020-07-15 19:21:47 0 [Note] InnoDB: Uses event mutexes

2020-07-15 19:21:47 0 [Note] InnoDB: Compressed tables use zlib 1.2.11

2020-07-15 19:21:47 0 [Note] InnoDB: Number of pools: 1

2020-07-15 19:21:47 0 [Note] InnoDB: Using SSE4.2 crc32 instructions

2020-07-15 19:21:47 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)

2020-07-15 19:21:47 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728

2020-07-15 19:21:47 0 [Note] InnoDB: Completed initialization of buffer pool

2020-07-15 19:21:47 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().

2020-07-15 19:21:48 0 [Note] InnoDB: 128 rollback segments are active.

2020-07-15 19:21:48 0 [Note] InnoDB: Creating shared tablespace for temporary tables

2020-07-15 19:21:48 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...

2020-07-15 19:21:49 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.

2020-07-15 19:21:49 0 [Note] InnoDB: 10.5.4 started; log sequence number 45041; transaction id 21

2020-07-15 19:21:49 0 [Note] Plugin 'FEEDBACK' is disabled.

2020-07-15 19:21:49 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool

2020-07-15 19:21:49 0 [Note] InnoDB: Buffer pool(s) load completed at 200715 19:21:49

2020-07-15 19:21:49 0 [Warning] 'user' entry 'root@5666e0d8e52e' ignored in --skip-name-resolve mode.

2020-07-15 19:21:49 0 [Warning] 'user' entry '@5666e0d8e52e' ignored in --skip-name-resolve mode.

2020-07-15 19:21:49 0 [Warning] 'proxies_priv' entry '@% root@5666e0d8e52e' ignored in --skip-name-resolve mode.

2020-07-15 19:21:49 0 [Note] Reading of all Master_info entries succeeded

2020-07-15 19:21:49 0 [Note] Added new Master_info '' to hash table

2020-07-15 19:21:49 0 [Note] mysqld: ready for connections.

Version: '10.5.4-MariaDB-1:10.5.4+maria~focal' socket: '/run/mysqld/mysqld.sock' port: 0 mariadb.org binary distribution

2020-07-15 19:21:49+00:00 [Note] [Entrypoint]: Temporary server started.

Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.

Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.

Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.

2020-07-15 19:21:58 5 [Warning] 'proxies_priv' entry '@% root@5666e0d8e52e' ignored in --skip-name-resolve mode.

2020-07-15 19:21:58+00:00 [Note] [Entrypoint]: Creating database wordpress23

2020-07-15 19:21:58+00:00 [Note] [Entrypoint]: Creating user root

ERROR 1396 (HY000) at line 1: Operation CREATE USER failed for 'root'@'%'

2020-07-15 19:21:34+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.4+maria~focal started.

2020-07-15 19:21:35+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'

2020-07-15 19:21:35+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.4+maria~focal started.

2020-07-15 19:21:35+00:00 [Note] [Entrypoint]: Initializing database files



PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !

To do so, start the server, then issue the following commands:


'/usr/bin/mysqladmin' -u root password 'new-password'

'/usr/bin/mysqladmin' -u root -h password 'new-password'


Alternatively you can run:

'/usr/bin/mysql_secure_installation'


which will also give you the option of removing the test

databases and anonymous user created by default. This is

strongly recommended for production servers.


See the MariaDB Knowledgebase at https://mariadb.com/kb or the

MySQL manual for more instructions.


Please report any problems at https://mariadb.org/jira


The latest information about MariaDB is available at https://mariadb.org/.

You can find additional information about the MySQL part at:

https://dev.mysql.com

Consider joining MariaDB's strong and vibrant community:

https://mariadb.org/get-involved/


2020-07-15 19:21:47+00:00 [Note] [Entrypoint]: Database files initialized

2020-07-15 19:21:47+00:00 [Note] [Entrypoint]: Starting temporary server

2020-07-15 19:21:47+00:00 [Note] [Entrypoint]: Waiting for server startup

2020-07-15 19:21:47 0 [Note] mysqld (mysqld 10.5.4-MariaDB-1:10.5.4+maria~focal) starting as process 107 ...

2020-07-15 19:21:47 0 [Note] InnoDB: Using Linux native AIO

2020-07-15 19:21:47 0 [Note] InnoDB: Uses event mutexes

2020-07-15 19:21:47 0 [Note] InnoDB: Compressed tables use zlib 1.2.11

2020-07-15 19:21:47 0 [Note] InnoDB: Number of pools: 1

2020-07-15 19:21:47 0 [Note] InnoDB: Using SSE4.2 crc32 instructions

2020-07-15 19:21:47 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)

2020-07-15 19:21:47 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728

2020-07-15 19:21:47 0 [Note] InnoDB: Completed initialization of buffer pool

2020-07-15 19:21:47 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().

2020-07-15 19:21:48 0 [Note] InnoDB: 128 rollback segments are active.

2020-07-15 19:21:48 0 [Note] InnoDB: Creating shared tablespace for temporary tables

2020-07-15 19:21:48 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...

2020-07-15 19:21:49 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.

2020-07-15 19:21:49 0 [Note] InnoDB: 10.5.4 started; log sequence number 45041; transaction id 21

2020-07-15 19:21:49 0 [Note] Plugin 'FEEDBACK' is disabled.

2020-07-15 19:21:49 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool

2020-07-15 19:21:49 0 [Note] InnoDB: Buffer pool(s) load completed at 200715 19:21:49

2020-07-15 19:21:49 0 [Warning] 'user' entry 'root@5666e0d8e52e' ignored in --skip-name-resolve mode.

2020-07-15 19:21:49 0 [Warning] 'user' entry '@5666e0d8e52e' ignored in --skip-name-resolve mode.

2020-07-15 19:21:49 0 [Warning] 'proxies_priv' entry '@% root@5666e0d8e52e' ignored in --skip-name-resolve mode.

2020-07-15 19:21:49 0 [Note] Reading of all Master_info entries succeeded

2020-07-15 19:21:49 0 [Note] Added new Master_info '' to hash table

2020-07-15 19:21:49 0 [Note] mysqld: ready for connections.

Version: '10.5.4-MariaDB-1:10.5.4+maria~focal' socket: '/run/mysqld/mysqld.sock' port: 0 mariadb.org binary distribution

2020-07-15 19:21:49+00:00 [Note] [Entrypoint]: Temporary server started.

Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.

Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.

Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.

2020-07-15 19:21:58 5 [Warning] 'proxies_priv' entry '@% root@5666e0d8e52e' ignored in --skip-name-resolve mode.

2020-07-15 19:21:58+00:00 [Note] [Entrypoint]: Creating database wordpress

2020-07-15 19:21:58+00:00 [Note] [Entrypoint]: Creating user root

ERROR 1396 (HY000) at line 1: Operation CREATE USER failed for 'root'@'%'

2020-07-15 19:21:59+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.4+maria~focal started.

2020-07-15 19:22:00+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'

2020-07-15 19:22:00+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.4+maria~focal started.

2020-07-15 19:22:01 0 [Note] mysqld (mysqld 10.5.4-MariaDB-1:10.5.4+maria~focal) starting as process 1 ...

2020-07-15 19:22:01 0 [Note] mysqld: Aria engine: starting recovery

recovered pages: 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% (0.3 seconds); tables to flush: 4 3 2 1 0

(0.0 seconds);

2020-07-15 19:22:01 0 [Note] mysqld: Aria engine: recovery done

2020-07-15 19:22:01 0 [Note] InnoDB: Using Linux native AIO

2020-07-15 19:22:01 0 [Note] InnoDB: Uses event mutexes

2020-07-15 19:22:01 0 [Note] InnoDB: Compressed tables use zlib 1.2.11

2020-07-15 19:22:01 0 [Note] InnoDB: Number of pools: 1

2020-07-15 19:22:01 0 [Note] InnoDB: Using SSE4.2 crc32 instructions

2020-07-15 19:22:01 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)

2020-07-15 19:22:01 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728

2020-07-15 19:22:01 0 [Note] InnoDB: Completed initialization of buffer pool

2020-07-15 19:22:01 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().

2020-07-15 19:22:01 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=45069

2020-07-15 19:22:01 0 [Note] InnoDB: 128 rollback segments are active.

2020-07-15 19:22:01 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"

2020-07-15 19:22:01 0 [Note] InnoDB: Creating shared tablespace for temporary tables

2020-07-15 19:22:01 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...

2020-07-15 19:22:02 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.

2020-07-15 19:22:02 0 [Note] InnoDB: 10.5.4 started; log sequence number 45081; transaction id 21

2020-07-15 19:22:02 0 [Note] Plugin 'FEEDBACK' is disabled.

2020-07-15 19:22:02 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool

2020-07-15 19:22:02 0 [Note] InnoDB: Buffer pool(s) load completed at 200715 19:22:02

2020-07-15 19:22:02 0 [Note] Server socket created on IP: '::'.

2020-07-15 19:22:02 0 [Warning] 'proxies_priv' entry '@% root@5666e0d8e52e' ignored in --skip-name-resolve mode.

2020-07-15 19:22:02 0 [Note] Reading of all Master_info entries succeeded

2020-07-15 19:22:02 0 [Note] Added new Master_info '' to hash table

2020-07-15 19:22:02 0 [Note] mysqld: ready for connections.

Version: '10.5.4-MariaDB-1:10.5.4+maria~focal' socket: '/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution

我登录了 db 容器的CLI,并确认我的init.sql脚本位于docker-entrypoint-initdb.d文件夹中:

I logged into the CLI for the db container, and verified that my init.sql script is in the docker-entrypoint-initdb.d folder:

$ cd docker-entrypoint-initdb.d
$ ls
init.sql
$ pwd
/docker-entrypoint-initdb.d

任何人都对其他需要检查的东西有想法吗?

Anyone have any ideas on what else to check?

推荐答案

我遇到了一个相同的问题,因此我对日志进行了更仔细的研究.我不确定下面的错误是否相关,但我决定摆脱它.

I faced an identical issue and I investigated the logs more closely. I wasn't sure if the following error was related but I decided to get rid of it.

ERROR 1396 (HY000) at line 1: Operation CREATE USER failed for 'root'@'%'

似乎默认情况下创建了 root 用户,因此我将用户的 environment 变量更改为 user 而不是>根:

It seems that root user is created by default so I changed the environment variable of the user to user for example instead of root:

MYSQL_USER: user

之后,我构建并运行 docer-compose.yml 文件,并成功执行了 SQL 脚本.

After that I built and run the docer-compose.yml file and the SQL scripts executed succesfuly.

这篇关于不执行docker-compose mariadb docker-entrypoint-initdb.d sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆