When I tried to launch a Docker container running MySQL with docker-compose, the container repeatedly restarted forever. Make a note of the solution to this problem here.
By the way, I had this problem when using Docker Toolbox on Windows, but it seems unlikely (probably) in other environments.
The settings of the part of docker-compose.yml where this problem occurs are as follows.
db:
image: mysql:5.7
volumes:
- "/tmp/db/data:/var/lib/mysql"
- "./db:/usr/src/db"
restart: always
environment:
MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
MYSQL_DATABASE: $MYSQL_DATABASE
MYSQL_USER: $MYSQL_USER
MYSQL_PASSWORD: $MYSQL_PASSWORD
ports:
- 3306:3306
No special settings are made, just the minimum required settings based on the image of mysql: 5.7
.
Execute --innodb-use-native-aio = 0
in the launched container. So docker-compose.yml looks like this:
db:
image: mysql:5.7
volumes:
- "/tmp/db/data:/var/lib/mysql"
- "./db:/usr/src/db"
restart: always
environment:
MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
MYSQL_DATABASE: $MYSQL_DATABASE
MYSQL_USER: $MYSQL_USER
MYSQL_PASSWORD: $MYSQL_PASSWORD
ports:
- 3306:3306
command: --innodb-use-native-aio=0 # <-this!
The MySQL Official Documentation has the following description.
InnoDB uses the asynchronous I/O subsystem (native AIO) on Linux to perform read-ahead and write requests for data file pages. This behavior is controlled by the innodb_use_native_aio configuration option, which applies to Linux systems only and is enabled by default.
InnoDB (the database engine for MySQL) is set to use Linux asynchronous I / O (native AIO) by default, but this behavior can be changed with the ʻinnodb_use_native_aio` option.
This time I was running the container on Windows using Docker Toolbox, but in that case this asynchronous I / O is not available, so it seems that an error occurred and the restart was repeated. Therefore, as stated in the quoted part above the official documentation, you need to set the ʻinnodb_use_native_aio` option to not use asynchronous I / O to avoid this problem.
The container restarts because I wrote restart: always
in docker-compose.yml. Otherwise, the container will fall normally.