D
D
driverx182019-12-08 17:19:07
Docker
driverx18, 2019-12-08 17:19:07

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

And the question is - if in fact this command is run through the php container, and I want to execute the mysqldump command, which should be run directly from the mysql container, how to organize this?
The method that makes the backup looks like this:
$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);

But, saving does not occur :(
However, if I execute this command in the VPS itself, then everything is saved. As I understand it, I need to somehow knock from one container to another container, how to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arman, 2019-12-08
@Arik

Maybe it's easier to separate?

* * * * * docker exec db mysqldump ... && docker exec app ...

L
lubezniy, 2019-12-08
@lubezniy

Do I understand correctly that the IP addresses (or domain names) of the containers are different? Add the host parameter so you can link the two containers and you'll be good to go.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question