-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow creating multiple databases on startup. #18
Conversation
I like it (as long as we go document how to do it with the proper syntax in |
Ping @tianon |
Seems reasonable, since database names can't have spaces in them. |
Well, in fact, they can: docs. TL;DR MySQL supports any Unicode character when quoted using back ticks. Not saying it's good practice, but it is supported. |
I'm not sure I'm comfortable with our script supporting such an obscene (but really only because I don't have a better idea for making this work |
@tianon yup agree, maybe document that it isn't supported is sufficient? Eg "known issues" or just "not supported". Just to prevent support questions 😄 |
Perhaps an approach like the I was just looking at this entrypoint and comparing it to https://github.com/cpuguy83/docker-mysql while thinking about how to make a simple, replication capable MySQL container for testing purposes. My first thought was that it would be nice to be able to add to |
Actually, it looks like I got hip to |
Nice find on the |
Unfortunately, after playing with it last night, I found that It's possible to work around this by manipulating the |
Maybe we should just deprecate MySQL and go for MariaDB 😄 |
As long as the image is still called "mysql". |
Oh, that sounds fun, though I think the MySQL people might get a bit grumpy if we just drop it. We could do |
I thought we were joking! I see no problem having a |
Yeah, thought we were joking as well, but adding an official MariaDB image to the repository might be a good thing (haven't checked if an official one exists to be honest) |
Looks like @tianon has an unofficial image here: https://github.com/tianon/dockerfiles/tree/master/mariadb |
There are others as well probably, but no (semi) official? |
Nothing in the Official Images (previously know as "stackbrew"). |
Totally off-topic, but I agree that MariaDB would need to be separate. |
@tianon reading back my comment; I meant to say; |
Back on topic, I like the "create multiple databases", though we should now add it to 5.6 as well, and then add docs to tell users how to use it (and not allow spaces in db names). |
Off topic: we need MariaDB. docker-library/official-images#294 |
Yeah, SGTM |
on topic; I like the "create multiple databases" as well. Is this all working correctly (looking back at the |
I think it should work fine in |
This will close both docker-library#18 and docker-library#24. The scripts are located in the /docker-entrypoint-initdb.d directory. Paired on this with @benkiefer
Hi all, I'm new to docker and trying out this image and I ran into a need to multiple databases. I've been sifting through this and other linked issues and for the life of me I can't parse what was settled on for best practice here. Do I need a new dockerfile that extends this one or can I specify multiple databases (or initdb scripts) in docker-compose.yml? Or something else entirely? Thanks for any guidance you can offer! |
@tfwright, you can have any number of initdb sql scripts, so that should be the easiest way to create multiple databases. |
@yosifkit Thanks. To confirm, right now I'm just using the image in my compose config, so I'll need to change that to point to a custom dockerfile, right? |
@tfwright, not necessarily, you could just have the sql file with the database creation in the directory with the compose file and add a |
@yosifkit I tried adding a simple script and volume directive
but docker complains when trying to start the container
What did I miss? |
I was able to fix the above by changing the volume directive to "./src/sql-setup.sql:/docker-entrypoint-initdb.d/sql-setup.sql" which doesn't jive with what I understand about docker's syntax...but who cares? It works! Thanks again! |
@tfwright not sure if there is a better way, but your suggestion worked for me ❤️ |
Came across this ticket, but saw that it is still open. I'm using a mysql container for rails development like this: docker run --name cpc-mysql -p 127.0.0.1:3307:3306 -e MYSQL_RANDOM_ROOT_PASSWORD=true -e MYSQL_USER=google_report -e MYSQL_PASSWORD=asdf -e MYSQL_DATABASE=app-dev -d mysql I would need a second database app-test for testing, what is currently the cleanest way to do this? |
Thanks for the pointer, I didn't see this option yet! In this case I will create a clean Dockerfile and add sql as needed. Thanks a lot! |
@thaJeztah one more thing, I read here (first answer): http://stackoverflow.com/questions/32482780/how-to-create-populated-mysql-docker-image-on-build-time that in the Dockerfile (build) it doesn't work - is this still true? If so, how should I do it? |
@solars correct; it's possible, but the |
@thaJeztah so I need to specify it in the run command above? or what is the suggested way to do it? |
Agreeing with #86 (comment), I think this is solved. Comment if you feel there is more to discuss. |
So how do we do multiple databases after all ? |
@Glideh, either a new container or add a script to |
The included script is idempotent, executed when the mysql container is initialized. This approach is borrowed from docker-library/mysql#18. ECOM-6563
The included script is idempotent, executed when the mysql container is initialized. This approach is borrowed from docker-library/mysql#18. ECOM-6563
I'm trying to follow the discussion here but it seems that the script in My
Mounted in
With
However, when I run
To be clear, using Anything I'm doing wrong? |
Yes, you are attempting to mount files as volumes. Here's a working example for PosgreSQL that has similar structure:
The |
This can be useful in some cases. For example, if you're auditing entities, and want to store the audit information on a separate database.