MariaDB / mariadb-docker

Docker Official Image packaging for MariaDB
https://mariadb.org
GNU General Public License v2.0
770 stars 438 forks source link

win+macOS: Cannot start a container with host directory as /var/lib/mysql mount #278

Closed iredmail closed 4 years ago

iredmail commented 4 years ago

Dear MariaDB developers and maintainers,

This is a known issue for years on both Windows and macOS platforms: can not start the mariadb container with host directory as /var/lib/mysql mount. Any possibility to fix it on MariaDB side? Without an external volume, it's impossible to run this docker image in production on Windows + macOS.

Related issues:

btw, running mariadb inside Alpine docker image has same issue.

wglambert commented 4 years ago

Linux Containers on Windows (LCOW) is an experimental feature not ready for production.

https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/linux-containers#bind-mounts

These applications all require volume mapping and will not start or run correctly.

  • MySQL
  • PostgreSQL
  • WordPress
  • Jenkins
  • MariaDB
  • RabbitMQ

https://docs.docker.com/v17.09/docker-for-windows/install/#download-docker-for-windows

. . . To run Docker Windows containers in production, see instructions for installing Docker EE on Windows Server 2016. To run Docker Linux containers in production, see instructions for installing Docker on Linux.

Docker for Mac is in the same boat. One thing you can try is using Docker named volumes instead of bind-mounts

wglambert commented 4 years ago

There's also a number of solutions in #95:

https://github.com/docker-library/mariadb/issues/95#issuecomment-359605090

Essentially, the best solution is to put /var/lib/mysql in a volume on your Docker VM (managed via docker volume xyz commands) instead of trying to share those files directly all the way back to your Mac or Windows host filesystem.

https://github.com/docker-library/mariadb/issues/95#issuecomment-365360318

Yeah, just use a named volume and connect it to more than one container.

https://github.com/docker-library/mariadb/issues/95#issuecomment-380243387

using a named volume is basically the only option to keep the database files when running MariaDB on Docker for Windows since the host-shared folder presented to the container does not behave in a standard way.

https://github.com/docker-library/mariadb/issues/95#issuecomment-407839431

We recently added #168 which should make sharing a directory from a windows host possible. Try the following (I don't have a host with Docker for Windows at the moment, but it worked when I last checked):

$ # also updated to specify a version of mariadb so that things don't break when latest becomes 10.4
$ docker run --name mariadb -d -v D:\Projects\docker\docker-qub:/var/lib/mysql -e MYSQL_USER=user -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=address -e >MYSQL_ROOT_PASSWORD=password mariadb:10.3 --innodb-flush-method=fsync

For future users that are using docker-compose it would be adding --innodb-flush-method=fsync to the command.


Going to close with what was said in that thread https://github.com/docker-library/mariadb/issues/95#issuecomment-380828108

Docker and MariaDB work fine together; the bit that doesn't work is the custom filesystem employed by Docker for Windows and Docker for Mac for sharing files across the VM boundary, which is not all that surprising for a database, which often use features like mmap for performance but thus also require support from the underlying filesystem. There are many reports of similar issues with vboxsf, for example.

https://github.com/docker-library/mariadb/issues/95#issuecomment-381205247

Any fixes would have to happen either in Docker's shared filesystem or in MariaDB itself (not something we can really fix in this Docker image), so I'd recommend checking their respective upstream bugtrackers for any discussion of fixing the problem.

iredmail commented 4 years ago

Thank you very much, @wglambert :)