[英]Docker importing a sql script on mysql container
How can this docker script be modified to allow a sql file to be imported into the mysql container?如何修改此 docker 脚本以允许将 sql 文件导入 mysql 容器? I need to modify the database on the mysql container.
我需要修改 mysql 容器上的数据库。
version: '3'
services:
devbox:
build:
context: ./
dockerfile: DevBox.DockerFile
ports:
- "80:80"
- "443:443"
volumes:
- .:/var/gen4
- ./offers:/var/www/vhosts/offers
devmysql:
image: mysql:5.7
platform: linux/x86_64
environment:
MYSQL_ROOT_PASSWORD: mypwd
MYSQL_DATABASE: offers
ports:
- "3306:3306"
restart: always
The official MySQL images support creating a volume called /docker-entrypoint-initdb.d/
官方 MySQL 镜像支持创建名为
/docker-entrypoint-initdb.d/
的卷
So in your devmysql
section of your compose file do something like this所以在你的撰写文件的
devmysql
部分做这样的事情
volumes:
- ./data:/docker-entrypoint-initdb.d/:ro
In this case, you'd want to have a data/
folder in the root of your project (wherever compose is being run from) and in that data/
folder you can put a SQL file with whatever commands you want.在这种情况下,您希望在项目的根目录中有一个
data/
文件夹(无论从哪里运行 compose),并且在该data/
文件夹中,您可以使用您想要的任何命令放置一个 SQL 文件。 They'll be run.他们将被运行。
If you're not running the official images, you might be able to create your own image that manually does something similar.如果您没有运行官方镜像,您也许可以创建自己的镜像来手动执行类似的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.