I've got a php container which hosts a Symfony web application. I need to use background scripts and initiate them from crontab. And it seems to work as long as I use root user. However, when I switch user to "www-data" - it stops working. My idea was to run php-fpm as user www-data and also log into "www-data" when I enter to the container. But crontab can be defined for root user, since it allows to prefix commands with username.
my entry point file contains:
#!/bin/bash
npm install
cron &
php-fpm
and my docker file looks like this:
WORKDIR /app
ADD ./entrypoint.sh /entrypoint.sh
RUN chmod 777 /entrypoint.sh
ADD ./crontab.txt /etc/cron.d/hello-cron
RUN chmod 0666 /etc/cron.d/hello-cron
RUN crontab /etc/cron.d/hello-cron
RUN touch /var/log/cron.log
RUN usermod -s /bin/bash www-data
USER www-data
ENTRYPOINT /entrypoint.sh
The above works if I skip line
USER www-data
But I would like to first initiate cron (for root) and later switch default container user to www-data... so I've tried also:
ENTRYPOINT /entrypoint.sh
USER www-data
But it doesn't work as well. Any help will be appreciated :)