N
N
N2021-03-14 14:02:30
Docker
N, 2021-03-14 14:02:30

Docker. docker-compose. Run via cron. How?

There is a server with a docker environment... everything works, everything is fine...

There is a container with MariaDB...

In cron I do two commands for testing:

*/5 * * * * cd /home/USER/ && /usr/local/bin/docker-compose -f prod-compose.yml exec mariadb /usr/bin/mysqldump -u USER -pPASSWORD --single-transaction DB_NAME | gzip > /home/USER/BACKUP/DB_$(date +%d-%m-%Y_%H_%M_%S).sql.tar.gz

*/5 * * * * touch /home/USER/BACKUP/test.txt


The first does NOT work ...
The second - all the rules.

At the same time, if you copy the first command and just run it in the console from under the same user, then everything works out the rules ...

Even I specifically blunted ... or the skis do not go ... :)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
N, 2021-03-16
@Fernus

In general, I won ... It was in the -T
flag to the docker-compose exec command. Why read the documentation for this flag . As a result, the command is:

*/5 * * * * cd /home/USER/ && /usr/local/bin/docker-compose -f prod-compose.yml exec -T mariadb /usr/bin/mysqldump -u USER -pPASSWORD --single-transaction DB_NAME | gzip > /home/USER/BACKUP/DB.sql.tar.gz

PS: Passing through cd is required...otherwise it won't work...if the paths in compose.yml are relative everywhere...and usually they are...

V
Vitaly Karasik, 2021-03-16
@vitaly_il1

1) look for errors when running from cron - in the mail if there is no redirect
2) try without a timestamp in the file name - I remember that there were some problems

D
Dmitry, 2021-03-14
@q2digger

Specify the full path to docker-compose

V
Vasily Shakhunov, 2021-03-14
@inf

Maybe so

*/5 * * * *  /usr/local/bin/docker-compose -f /home/USER/prod-compose.yml exec mariadb /usr/bin/mysqldump -u USER -pPASSWORD --single-transaction DB_NAME | gzip > /home/USER/BACKUP/DB_$(date +%d-%m-%Y_%H_%M_%S).sql.tar.gz

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question