Issue
I have a crontab set up to run a python script called from a docker-compose command:
* * * * * cd path/to/repo && docker-compose run worker python -c "from directory.module import test_function; test_function()"
The module & test_function looks like this:
import logger
def test_function():
logger.info('Hello')
The docker container is up and running. However, when I go to check my log file, nothing has been written to it. I'm not sure what I need to do to get this working correctly.
Solution
So, I created a shell script (test_cronjob.sh
) to run the commands I need.
#!/bin/bash
PATH=/usr/local/bin/
docker-compose -f /full/path/to/docker-compose.yml run worker python -c "from directory.module import test_function; test_function()"
And edited my crontab -e
:
* * * * * /bin/sh /full/path/to/test_cronjob.sh
Or just simply editing the crontab -e
without the shell script, like below:
* * * * * PATH=/usr/local/bin/ docker-compose -f /full/path/to/docker-compose.yml run worker python -c "from directory.module import test_function; test_function()"
Answered By - Kevin G Answer Checked By - Pedro (WPSolving Volunteer)