'Crontab has no access to docker commands [closed]
Recently I started working on Ubuntu 18.04.4 LTS machine. I have created a small project which should run from a docker container with command:
docker run docker_name "2022-04-11"
This command runs like a charm when I run it manually (I have sudo permissions), but breaks when I try to run it from sudo crontab.
I tried to log all output from the crontab to file myjob.log with command:
0 1 * * * docker run docker_name "2022-04-11" >> /home/projects/project/myjob.log 2>&1
Then I saw that myjob.log file contains an error message:
/bin/sh: 1: docker: not found
It got me confused. Why I can run docker commands, but crontab can't?
Solution 1:[1]
Check you crontab you are probably missing something like:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
If you are running as your user not root you have to add it to the top.
The short of it is that your $PATH isn't set so you can't find the docker command.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JJ Asghar |
