Direkt zum Inhalt

EC2 ubuntu crob job failure

0

Hi,

I’m trying to set up a cron job on an Ubuntu EC2 instance, but it keeps failing with a Permission denied error.

These are the steps I followed:

  1. Edited the crontab:

    crontab -e
    
  2. Added the following entry to run every minute for testing:

    * * * * * /usr/bin/docker system prune -af
    
  3. Verified the entry was saved:

    crontab -l
    

The cron service is running, but when I check the logs I see:

Mar 10 18:06:01 remote-docker-engine-amd-01 cron[19243]: Permission denied
Mar 10 18:06:01 remote-docker-engine-amd-01 CRON[19243]: Permission denied

The command itself works when I run it manually as the same user:

/usr/bin/docker system prune -af

So Docker permissions seem fine when executed interactively, but the job fails when triggered by cron.

I also tried reinstalling the cron package, but the issue persists.

Am I missing something in the cron configuration or environment? Any guidance would be appreciated.

Thanks.

gefragt vor 3 Monaten95 Aufrufe

2 Antworten
1

Hello.

Even if I set "sudo" in the command set in cron, it fails to execute?
If you run it as the root user, it should generally run successfully.
To troubleshoot, start by enabling sudo.
https://stackoverflow.com/questions/70099692/crontab-sudo-docker-permission-denied

EXPERTE

beantwortet vor 3 Monaten

AWS
EXPERTE

überprüft vor 3 Monaten

0

When you run docker commands interactively, your shell session has access to the Docker socket (usually docker.sock) because your user is in the docker group. However, cron jobs run in a minimal environment without loading group memberships the same way.

For a quick fix, try to run the cron job as root:

sudo crontab -e

AWS

beantwortet vor 3 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.