-
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
Cannot persist the data by doing docker commit #44
Comments
In your example, you're not using a bind-mount, because of this, docker will create a new (empty) volume and the mysql container will initialise a new database. The Dockerfile of the mysql image contains a volume definition for the mysql-data (https://github.com/docker-library/mysql/blob/master/5.7/Dockerfile#L35), so the data itself will never be included in the container itself, but also won't be deleted if you delete the container (unless doing Possible solutions;
Let me know if you need more help with this. Also wondering, what was your reason to commit the container? Were you trying to commit the database so that you could "clone" the container and have a second container with the same data in it? |
Thanks for your quick reply! |
Yes, I noticed that you used bind-mounted volumes in your first part. You weren't using them in the "long" example. I also just noticed you're starting the container with I think something like this should work;
Untested, just "from the top of my head". To export/import your database, here's some (unfinished) notes I made a while ago that may be useful; |
Thanks again for your quick reply. I just tried the following. Would you know why I got the error regarding running mysqld as root?
(yes, -it is only for debugging) |
Interesting, I got the same error with update; docker run -d -h mysql --name mysqltmount_all_dir -v $PWD/mysql/var/lib/mysql:/var/lib/mysql -v $PWD/mysql/etc/mysql:/etc/mysql -e MYSQL_ROOT_PASSWORD=test -e MYSQL_USER=mmx -e MYSQL_PASSWORD=mmx -e MYSQL_DATABASE=mmx mysql:5.6.21
Checking logs of the first start; docker logs mysqltmount_all_dir
...
2015-01-28 20:56:40 1 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2888b34e-a730-11e4-8a66-0242ac110037.
2
....
2015-01-28 20:56:40 1 [Note] Execution of init_file '/tmp/mysql-first-time.sql' started.
2015-01-28 20:56:40 1 [Note] Execution of init_file '/tmp/mysql-first-time.sql' ended.
2015-01-28 20:56:40 1 [Note] mysqld: ready for connections.
Version: '5.6.21' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server (GPL) Remove the first container and start a new one docker stop mysqltmount_all_dir
docker rm mysqltmount_all_dir
docker run -d -h mysql --name mysqltmount_all_dir -v $PWD/mysql/var/lib/mysql:/var/lib/mysql -v $PWD/mysql/etc/mysql:/etc/mysql -e MYSQL_ROOT_PASSWORD=test -e MYSQL_USER=mmx -e MYSQL_PASSWORD=mmx -e MYSQL_DATABASE=mmx mysql:5.6.21 And check the logs of the second/new container docker logs mysqltmount_all_dir
...
2015-01-28 20:57:37 1 [Note] Event Scheduler: Loaded 0 events
2015-01-28 20:57:37 1 [Note] mysqld: ready for connections.
Version: '5.6.21' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server (GPL) So, yes, there seems to be an issue with |
Created a separate issue for the "root" problem here: #45 |
Hi, thanks so much for your support. I think there may be something subtle happening here. I copied and pasted your command and it still failed for me:
|
I am quite sure this is related to bind mounting over the config dir: 12ffb2f#commitcomment-9444466 |
@skwokmag My However, the "root" problem is because of a recent change in the MySQL image as @yosifkit mentioned. I forgot about that. The problem occurs if you bind-mount the whole mysql configuration directory. Not doing that, will make it work also with the
Also see the link that @yosifkit added (12ffb2f#commitcomment-9444466), that explains how to mount the configuration if you have to. I hope you find your way around with these examples. I don't think there's an issue with the MySQL image and I suggest to close this issue (the GitHub issue tracker is not really meant as a support forum 😄) |
Hi @thaJeztah , I am not sure why but it still failed for me:
|
I think your problem there is running the container interactively and with a TTY ( (at least, I got the same result when running with |
Hi @thaJeztah , This is what I got with using '-d' instead of '-it':
|
because you named your container
If you're running on a host with limited memory, and the container stops during the startup, you may have to enable swap. See this ticket for more information on that; #3 |
Hi @thaJeztah , yes you are right, I used a wrong container name there. I have corrected that and here is the new screen output:
Please note that I have already shared the dir in Virtual box by executing: Would it be possible that it is related to: |
FYI, I ran bash with the container and saw the followings (please note the group:user of the mysql dir): root@mysql1:/# ls -la /var/lib/ |
The problem you're having there is most likely caused by the fact you're using the VirtualBox shared folder. Docker will always preserve the uid/gid of the host when mounting a volume. You can try to chown those before using, but even then the performance will be really bad (VirtualBox shared folders are really slow) Anyway, these are not issues that can be solved by the MySQL image; I suggest to use a regular mounted host directory, not a VBox shared folder and browse the boot2docker issue tracker for tips on working with the VBox shares, because there are a lot of issues with those. |
What's the best approach for solving this? I'm simply trying to mount the data directory of the container's to the host one |
Mounting the data-directory of a container to the "host" should work. But if you're using Boot2Docker and the directory on the "host" (host being the VirtualBox VM) is a VirtualBox shared folder, permissions can become tricky. At least, that's what I've heard in various places (I don't use Boot2Docker myself). |
I'm using Boot2Docker on OSX and from what I understand, one of the main benefits of Boot2docker is to abstract the mounting of volumes from your host machine into the docker containers through some sort of mapping between the VBox folders and your host folders. I'm not sure about the internals of such abstraction. |
@mikeys Boot2Docker creates a VirtualBox share of Really what it does is automatically mount a VirtualBox share named The problem is that these shares are owned by the This is only a problem with Boot2Docker because it uses the virtual box sharing, which changes the uid of the share to the In Vagrant, I usually solved this by changing my Vagrant file to use different permissions for the virtual box share: config.vm.synced_folder ".", "/vagrant", :mount_options => ['dmode=777,fmode=666'] Maybe you could do something like that inside of your Boot2Docker image, I haven't looked into it. I think you would make these changes to One way I solved this was to just set my containers up so that I could configure them with the UID I wanted them to run their processes as, so I could just set it to 1000. The downside to this is that you basically need to create your own images for everything since most containers I've found don't let you do this. I hope this helps. |
Thanks for helping out, @caleb! Didn't have the right info at hand to give a helpful answer myself. |
I built my own Boot2Docker iso that mounts filesystems with more liberal permissions, it was very easy: Clone https://github.com/boot2docker/boot2docker Edit mountOptions='defaults' to mountOptions='defaults,dmode=777,fmode=666' Then build the image with your existing boot2docker installation and write the iso to the current directory: docker build -t boot2docker . && docker run --rm boot2docker > boot2docker.iso Then you can destroy your current boot2docker vm: Then copy the new iso to your ~/.boot2docker directory: Then re-init your boot2docker VM: There you go, when you ssh into your boot2docker vm now, all the directories will be |
@caleb interesting. Given that Boot2Docker + VBox will (probably) only be used for development setups, this might actually be a nice (although duct-tape-ish) workaround that saves many people headaches. Have you discussed that solution in the Boot2Docker repository? I think you should; to see what the maintainers think of it? |
@thaJeztah I played around with those same |
Ouch! Yup that's not handy. Bummer, because that would have reduced a lot of support questions wrt b2d. Otoh, is the situation worse than the current case? |
@thaJeztah if you're implying that the situation is in fact better with |
I knew that would be a problem, but I just store uploaded files, databases, etc inside of shared volumes, so the executable bit is not important to me (maybe except for shell scripts, but you can always run them through the interpreter). Maybe this shouldn't be a default, but I believe that for me it's better that the mysql container can write to a mounted directory. In production you have to worry about permissions as well, but you can just chown/chmod the directories to fit your needs, whereas And of course, the other solution is to just use data containers (that live inside the b2d VM) and samba containers to peek into them when you need to. This is something that I haven't looked into yet. |
@md5 yeah. I'm really not sure what's best here. In the end, VBox sharing in itself was added as a stop-gap solution until something better was implemented. I see numerous questions come by from people running into both performance and permission problems. It's hard to explain, especially to people not fully understanding the relation to their workstation (OS X) and the boot2docker VM, let alone volumes and containers. So anything that would make it work better "out of the box" would be welcome. Not sure if this is the way to go either. |
Thanks @caleb, your solution worded for me on box
|
None of these are great solution to me because it requires everyone to modify the base box every time the install a new version or like just recently with docker toolbox you would have to do the above again to configure file permissions. I just copy /usr/local/var/mysql/* into the volume i am going to mount and then chmod 664 the whole folder. |
@skwokmag, just add docker run --name mysql -v $PWD/var/lib/mysql:/var/lib/mysql -v $PWD/etc/mysql:/etc/mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --user 1000 mysql:5.7.13 an you'll get this: ...
2016-07-28T10:40:31.770773Z 0 [Note] mysqld: ready for connections.
Version: '5.7.13' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL) |
Also note that the permissions issue should be solved by Docker for Mac |
Hi, docker run --name mysqlt1 -h mysql --rm -it -v ~/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=pass -e MYSQL_USER=pass -e MYSQL_PASSWORD=pass -e MYSQL_DATABASE=pass_dev mysql:5.7 |
@brlo that worked for me! Thanks |
Hi,
Please help! This is urgent to me.
I have tried to start the mysql image (5.6.22) in a couple of ways:
Then, I commit the image, stop the old one, and start the new image by executing the same docker run command with the tag replaced with the new image's.
Result:
Every time when the new image starts, it will execute /tmp/mysql-first-time.sql and so the data is removed.
What I'd like to achieve is to persist the data inside the container. In the mounted volume is fine as well.
Startup Logs:
Env:
Os: OSX 10.10.1
Docker: Docker version 1.3.1, build 4e9bbfa
Boot2Docker-cli version: v1.3.1
Git commit: 57ccdb8
Thanks so much!
The text was updated successfully, but these errors were encountered: