I'm running docker on AWS AMI and getting following error while I want to run mysql:8 container using docker-compose
. I have created the data volume this container needs.
Snip of my docker-compose file is
version: '3.7'
services:
mysql:
image: mysql:8
command: bash -c "rm /etc/localtime && ln -s /usr/share/zoneinfo/America/New_York /etc/localtime && mysqld --user=root --default-authentication-plugin=mysql_native_password"
volumes:
- mysql-data:/var/lib/mysql
- ./:/home
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: example
...
mysql-data:
external:
name: data-volume
and I get following error, I'm not sure what data directory is the error referring to
mysql_1 | 2019-09-20T03:13:24.151141Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161)
mysql_1 | 2019-09-20T03:13:24.151148Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000)
mysql_1 | 2019-09-20T03:13:24.433348Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
mysql_1 | 2019-09-20T03:13:24.433434Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.17) starting as process 1
mysql_1 | 2019-09-20T03:13:24.443292Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory.
mysql_1 | 2019-09-20T03:13:24.443383Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
mysql_1 | 2019-09-20T03:13:24.445787Z 0 [ERROR] [MY-010119] [Server] Aborting
mysql_1 | 2019-09-20T03:13:24.446197Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.17) MySQL Community Server - GPL.
Your docker-compose.yml
overrides the CMD
defined in the official MySql Dockerfile
(i.e ["mysqld]"
). The default entrypoint (docker-entrypoint.sh)
does not initialize the container if the command doesn't start with mysqld
(mysqld
should be the first argument of the entrypoint script). As a consequence the data directory doesn't get created, hence the error. The data directory is the directory where the database files are created.
To run with the custom command
configured in the compose file you should initialize the mysql-data
volume before starting the container:
docker run --rm \
--name init-mysql \
-v mysql-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD="example" \
mysql:8
Then stop the container
docker stop init-mysql
Start again the container using docker-compose
.
In alternative you could write a custom entrypoint. Hope it helps