更新时间:2023-09-19 11:31:52
考虑到您已经显示了整个启动日志,似乎您已经针对已存在的 db_data
卷启动了mysql容器包含一个mysql数据库文件系统.
Taking for granted you have shown your entire start log, it appears you started your mysql container against a pre-existing db_data
volume already containing a mysql database filesystem.
在这种情况下,绝对不会在容器启动时初始化任何内容,并且环境变量无用.在环境变量"中引用官方图像文档.部分:
In this case, absolutely nothing will be initialized on container start and environment variables are useless. Quoting the official image documentation in the "Environment Variables" section:
请注意,如果使用已包含数据库的数据目录启动容器,则以下任何变量都不会起作用:在容器启动时,任何现有数据库都将保持不变.
Do note that none of the variables below will have any effect if you start the container with a data directory that already contains a database: any pre-existing database will always be left untouched on container startup.
如果要初始化实例,则必须从头开始.当使用命名卷时,使用docker compose很容易,就像您的情况一样.警告:这将永久删除您的 db_data
卷中的内容,并清除您以前在那里拥有的任何数据库.如果需要保留内容,请先创建一个备份.
If you want your instance to be initialized, you have to start from scratch. It is quite easy to do with docker compose when using a named volume like in your case. Warning: this will permanently delete the contents in your db_data
volume, wiping out any previous database you had there. Create a backup first if you need to keep the contents.
docker-compose down -v
docker-compose up -d
如果您转换为绑定安装,则必须自己删除其所有内容(即 rm -rf/path/to/bind/mount/*
)
If you ever convert to a bind mount, you will have to delete all it's content yourself (i.e. rm -rf /path/to/bind/mount/*
)
注意:许多其他官方db docker映像(postgres,mongo ....)也以类似的方式工作.
Note: many other official db docker images (postgres, mongo....) work a similar way.