简体   繁体   中英

Docker toolbox with mysql container problem on Windows 10 Home (and Pro)

I unable to run MySQL containers made from MySQL images with database volumes mapped to my host machine's folder.

It doesn't matter if the host folder is empty or with existing database files. I do know that Docker Toolbox could mount volumes on Windows only from c:\\Users\\ so my test folder is under that one.

I was trying different (official and not) MySQL images from 5.5 to latest with no result. Anytime when location /var/lib/mysql in container is pointing to a folder on my host machine (c:\\Users\\someuser\\testfolder) I've got an error on container`s running with InnoDB error ("InnoDB: Operating system error number 22 in a file operation" or "InnoDB: File ./ib_logfile0: 'aio write' returned OS error 122").

I was trying to modify mysql container's /etc/my.cnf (under [mysqld] section, using "docker cp" command) adding "innodb_use_native_aio=OFF" or (sometimes even and) "innodb_use_native_aio=0" keys and even was trying to run "docker run" with "--user 1000:50" with no result either.

Just after I delete mount point from container's /var/lib/mysql to my host folder, the container runs normally.

There are many alike questions but no one has complete step by step solution how to run a MySQL container with a Docker Toolbox under Windows 10 (Home & Pro) to bring container work with an existing database on the host's volumes.

It took me a while to get an answer but finally everything worked! For those who are new to Docker and have problems mounting MySQL folder to the host here is a short guide. Please note I chose bitnami/mysql image for my experiments (for another images folders can be differ).

  1. Create a folder c:\\Users\\[YourAccount]\\MySQLData for MySQL data.
  2. Create a folder c:\\Users\\[YourAccount]\\MySQLConf for a custom MySQL config file.
  3. Create a custom MySQL config file c:\\Users\\[YourAccount]\\MySQLConf\\my_custom.cnf and add two lines in it:
[mysqld]
innodb_use_native_aio=0
4. Now create and run the container mounting your custom config and data folder to it:
 docker run -d --name mysql -e ALLOW_EMPTY_PASSWORD="yes" \\ -v //c/Users/[YourAccount]/MySQLData:/bitnami/mysql/data \\ -v //c/Users/[YourAccount]/MySQLConf/my_custom.cnf:/opt/bitnami/mysql/conf/my_custom.cnf:ro \\ bitnami/mysql:latest 

Hooray!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM