Ir para o conteúdo

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.

feita há 3 meses95 visualizações
2 Respostas
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

ESPECIALISTA
respondido há 3 meses
AWS
ESPECIALISTA
avaliado há 3 meses
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
respondido há 3 meses

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.