vlauciani's avatar

DockerSwarm/Kubernetes - MySQL container restart empty

Hi I’m using Laravel with docker swarm (or with kubernetes); to simplify my problem, consider that we have two containers:

  • laravel app
  • mysql (used only for horizon job, no need persistent volume)

the problem is that when the MySQL container crashes and will be restarted by the orchestrator, It doesn’t contain the migrations because the DB is empty.

To solve that I’ve simply added into app/Console/Kernel.php the code:

        $schedule->command('migrate')
            ->name('schedule__migrate')
            ->withoutOverlapping()
            ->everyMinute();

it works but the question is; is this the best practice to run migration when the MySQL restarts?

Thank you.

0 likes
1 reply
Tray2's avatar

You have ovethought the whole thing, Just use a simple SQLite db on the local host instead, or set up a permanent container. Stop using all those fancy kubernetes things, they will only make you get wird issues like this one.

Please or to participate in this conversation.