After changing my php-fpm service to run as a regular user instead of root, I can’t get my cron to run anymore.
Heres my docker-compose.yml:
version: "3.8"
services:
# Application
myservice:
build:
context: ./docker/services/app
dockerfile: app.dockerfile
working_dir: /var/www
user: "1000:1000"
volumes:
- ./src:/var/www
networks:
- network
And from my dockerfile:
FROM php:8.1-fpm
WORKDIR /var/www
# Install Cron
RUN apt-get update && apt-get install -y cron
RUN echo "* * * * * root php /var/www/artisan schedule:run >> /var/log/cron.log 2>&1" >> /etc/crontab
RUN touch /var/log/cron.log
CMD bash -c "cron && php-fpm"
This worked perfectly before adding the user: “1000:1000” to my docker-compose.yml, but now the service just crashes with the following error:
2023-04-13 12:43:00 bash: line 1: cron: command not found
Any idea what might cause this?