Reputation: 2396
I'm using a docker container for MySQL with docker-compose that works just fine.
The only problem is that I get the error unknown database "database_name"
the first time I run it every day (after Windows startup)
After that, if I stop it and re-run it I get no errors and everything works fine.
yaml configuration:
version: "2.0"
services:
mysql:
container_name: mysql
restart: always
image: mysql:5.7
command: --max_allowed_packet=32505856
ports:
- "3306:3306"
volumes:
- 'C:\data\mysql_db:/var/lib/mysql/'
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
networks:
- shared
networks:
shared:
external:
name: shared
EDIT: here is a pastebin of the logs of a startup: https://pastebin.com/aJiKJ4aE
Upvotes: 6
Views: 10382
Reputation: 3
The problem is that there is no such a schema in your database container instance. What you can do is:
You should be able to access the container db now.
check this video if you don't know how to connect to the database container using the workbench
Upvotes: 0
Reputation: 1692
I believe you're experiencing this problem. There's a couple possible solutions there, but I haven't tried them myself as I don't have Docker on Windows:
restart:always
from your container. Instead run this command once, it'll create a container that will start your container when the mount is ready: docker run --name holdup
--restart always
-v 'C:\data\mysql_db:/var/lib/mysql/'
-v //var/run/docker.sock:/var/run/docker.sock
shaynesweeney/holdup
This will however have an effect of starting all your stopped containers on reboot.
Do {
$dockerps = (docker ps)
Start-Sleep -S 5
} While (! $dockerps -contains "mysql")
Set-Location D:\Docker\MySQL
docker-compose restart
Then:
Add a Task Scheduler Task with the action Start a program to run the script.
Program/script: powershell.exe
Add arguments: -windowstyle hidden -file D:\Docker\MySQL-Restart.ps1
Upvotes: 3