This shell script (as example) is never executed by crontab unless the docker-compose commands are commented. If is executed standalone it runs.
#!/bin/sh
# arg0 start-channel
# arg1 channel name
cd $HOME/$1
docker-compose ps
docker-compose up -d
docker-compose ps
exit 0
Had the same problem when adding docker-compose
commands to crontab. Worked around by launching individual docker
counterparts.
This is unlikely to be an issue with docker-compose
. It's good practice to use absolute paths in crontabs because your $PATH may not be the same as an interactive shell. Maybe add set -x
to see why it's failing?
Exactly, using absolute paths (/usr/local/bin/docker-compose) inside shell scripts it runs.
Thanks!
I Faced the same problem, simplest solution is to add path at beginning of crontab (note that last path is where docker-compose is) :
PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin
For anyone facing this issue, it's probably a small mistake. Try the following:
cd
to your (absolute) path to docker-compose.yml
in your shell script before docker-compose
馃槂
Thank you for this post. I was struggling until I stumbled upon this post. I am using absolute path /usr/local/bin
.
Thanks for this post guys this problem was killing me. This is what I had to do:
Exactly, using absolute paths (/usr/local/bin/docker-compose) inside shell scripts it runs.
Thanks!
thanks! works too when add absolute path like above !
for me a docker command was not working error: /bin/sh: 1: docker: not found
.
so i ran which docker
and got /snap/bin/docker
. replaced docker
with /snap/bin/docker
in crontab
DC_NOT_DEFINED=1
if hash docker-compose 2>/dev/null; then
DC_NOT_DEFINED=0
fi;
if [[ ${DC_NOT_DEFINED} > 0 ]]; then
echo "* docker-compose not defined, make alias"
docker-compose() {
/usr/local/bin/docker-compose "$@"
}
export -f docker-compose
docker-compose -v
fi;
If anyone is having issues with docker-compose run
or docker-compose exec
the -T
flag did it for me:
/usr/local/bin/docker-compose exec -T web sh
For anyone facing this issue, it's probably a small mistake. Try the following:
- make sure that you
cd
to your (absolute) path todocker-compose.yml
in your shell script beforedocker-compose
- just use absolute paths everywhere
馃槂
Thanks! 2 days debugging and this is works like a charm!
/usr/local/bin/docker-compose -f /your/docker-compose.yml/file/path exec -T web python3 script.py
Most helpful comment
Exactly, using absolute paths (/usr/local/bin/docker-compose) inside shell scripts it runs.
Thanks!