I have a docker-compose.yml
file that runs 3 services, front-end, back-end and a MySQL database.
The database service has a volume, but every time I run the orchestration again, I get these errors:
2024-05-29T21:24:08.765810Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting. 2024-05-29T21:24:08.765820Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it. 2024-05-29T21:24:08.765885Z 0 [ERROR] [MY-010119] [Server] Aborting
According to the error, it can’t initialize the server because the volume directory already has files in it, but how will I persist the data between initializations if I will have to erase the data before? Or how can I make the MySQL image not use the --initialize
argument on start up?
This is the MySQL service:
`db:
image: mysql:8.0.21
container_name: db
platform: linux/x86_64
ports:
– 3306:3002
environment:
– MYSQL_ROOT_PASSWORD=stackoverflow
restart: ‘always’
healthcheck:
test: [“CMD”, “mysqladmin” ,”ping”, “-h”, “localhost”]
timeout: 10s
retries: 5
cap_add:
– SYS_NICE
volumes:
– db_data:/var/lib/mysql
entrypoint: /bin/bash -c “if [ ! -d ‘/var/lib/mysql/mysql’ ]; then mysqld –initialize; fi && exec mysqld”
volumes:
db_data: `
As you can see in the docker-compose.yml
file, I made a custom entry point /bin/bash -c "if [ ! -d '/var/lib/mysql/mysql' ]; then mysqld --initialize; fi && exec mysqld"
to try to run a different command in case there are files in the directory, it didn’t work. I’m new to this so it can easily be wrong.