Answer the question
In order to leave comments, you need to log in
How to access mysql container from php container?
I want to make a script that makes backups of the database and saves it in a certain path by running cron 2 times a day.
Using Laravel, I put a command in vps in the cron file that will pull other cron commands that I will create through Laravel:
* * * * * docker exec app /var/www/artisan schedule:run >> /dev/null 2>&1
$filename = 'backup-' . date("Y-m-d_h_i_s") . '.sql';
$command = "docker exec db mysqldump --user=" . env('DB_USERNAME') ." --password=" . env('DB_PASSWORD') . " " . env('DB_DATABASE') . " | gzip > " . "/var/backups/" . $filename;
$returnVar = null;
$output = null;
exec($command, $output, $returnVar);
Answer the question
In order to leave comments, you need to log in
Maybe it's easier to separate?
* * * * * docker exec db mysqldump ... && docker exec app ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question