Docker-compose with crontab

I recently had a problem when I want to execute the docker-compose command in crontab.

I have a YAML file containing dockers that define all the services I need, for example "docker-compose.yml". And I also have a Makefile in which I wrote some command to do something.

My makefile:

.PHONY operate
operate:
    /usr/local/bin/docker-compose -p /project -f ~/docker-compose-production.yml run rails env

This make script worked fine when it was executed in the shell. He listed the entire var I environment defined in the docker-compose.yml file. But when I put it in crontab. The result became strange: there is nothing in it, but only $PATH.

My crontab file:

57 21 * * * make -f ~/Makefile operate  >~/temp 2>&1

I suppose there should be some kind of var environment that docker-compose should have, but I don't know. Do you have an idea about this problem?

+5
5

Docker Compost, Docker. , Docker.

, cron , Docker. , Makefile, . "whoami" .

+1

. , PATH var crontab , .

0

10 3 * * 0/usr/local/bin/docker-compose -f/www/ilanni.com/docker-compose.yml start>/dev/null

0

I am using docker-compose on Windows 10 with crontab WSL (Windows Subsystem for Linux). Note: Docker Desktop for Windows and WSK work without problems using https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly

Documenting how I ran docker-compose commands for anyone who might run into the same problem.

# Setting environment for Docker
DOCKER_HOST=tcp://localhost:2375
# m h  dom mon dow   command
01 01 * * * cd /d/my_docker_proj_dir && /home/my_user/.local/bin/docker-compose  exec -d container bash  -c "full-path-to-command args" 1> /tmp/cron.log 2> /tmp/cron.log
0
source

You have to create crontab using sudo and continue

0
source

All Articles