• Uncategorized

About linux : Crontab-has-no-access-to-docker-commands-closed

Question Detail

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?

Question Answer

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.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.