-
Set up a
docker-compose.yaml
file (file content at the bottom of this page). -
Also create a
data/mysql
folder in your project. -
In order to set up a volume for MySQL in Docker Toolbox, we will need a VirtualBox Shared Folder, just like mentioned in Fixing Volumes in Docker Toolbox.
VirtualBox by default has a
c/Users
Shared Folder that we can use for this (as long as your project is withinC:\Users
. Verify that this shared folder is set up properly:
-
Add a new volume to the
mydatabase
service in thedocker-compose.yaml
for the database files. Because we are using docker-toolbox and VirtualBox, we need an absolute path, starting with//c/
:volumes: - //c/Users/your_username/projects/wordpress-docker-stack/data/mysql:/var/lib/mysql
-
If you were to start the containers now, it would create some files within the
data/mysql
folder, but it would quickly run into problems because of the asynchronous I/O subsystem used by InnoDB.It would show you an error message like
Operating system error number 22 in a file operation.
orOperating system error number 22 in a file operation.
orFile ./undo_001: 'aio write' returned OS error 122
:
Side note: Confusingly, if you were to try re-running the database after the initial files have been created but before the asynchronous issue has been resolved, it will show you an error message like--initialize specified but the data directory has files in it
orThe designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
. Thedata/mysql
directory needs to be empty for the first setup of MySQL:
-
In order to disable the asynchronous I/O subsystem feature to make InnoDB work with the VirtualBox shared folder, a MySQL config file can be created, as mentioned on Issues with Docker db images on Windows 10 Home.
First, add an additional volume:
- //c/Users/your_username/projects/wordpress-docker-stack/data/conf:/etc/mysql/conf.d
-
Then create the folder
data/conf
and add a file calledlocal.cnf
with the contents:[mysqld] innodb_use_native_aio=0
-
Then, find this file in Windows Explorer and make it Read-only:
The reason for this is that MySQL requires that the file is read-only. If we don't do this, it will complain with errors like[Warning] World-writable config file '/etc/mysql/conf.d/local.cnf' is ignored.
:
-
Now WordPress and MySQL should run when you start the containers! 🎉
Forked from kunstloch/_windows-10-home-docker-toolbox-wordpress-mysql-with-volume.md
Created
October 17, 2019 13:47
-
-
Save karlhorky/91ab5c0b2d49a022937bab11d3cf8531 to your computer and use it in GitHub Desktop.
Setting up WordPress and MySQL on Windows 10 Home (Docker Toolbox)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
mywordpress: | |
image: wordpress | |
environment: | |
WORDPRESS_DB_HOST: 'mydatabase' | |
WORDPRESS_DB_NAME: 'wordpress_db' | |
WORDPRESS_DB_USER: 'wordpress_user' | |
WORDPRESS_DB_PASSWORD: 'my-secret-wordpress-pw' | |
ports: | |
- 8080:80 | |
networks: | |
- mynetwork | |
mydatabase: | |
image: mysql | |
environment: | |
MYSQL_ROOT_PASSWORD: 'my-secret-root-pw' | |
MYSQL_DATABASE: 'wordpress_db' | |
MYSQL_USER: 'wordpress_user' | |
MYSQL_PASSWORD: 'my-secret-wordpress-pw' | |
command: --default-authentication-plugin=mysql_native_password | |
networks: | |
- mynetwork | |
networks: | |
mynetwork: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment