Reputation: 1607
I have an docker container running with Apache. This was started with docker-compose under the root user. In this container de webserver runs under the default user www-data. Via conjob I trigger the php script for uploading images. This works fine if the cronjob runs under root. But I want to have the conjob running under www-data so the uploaded files have the same owner as files that are uploaded directly via apache.
I use the following cronjob (this works):
*/1 * * * * docker exec apache_1 php /var/www/import
But when I change the cronjob user to www-data (does not trigger anymore):
*/1 * * * * www-data docker exec apache_1 php /var/www/import
With the last cronjob the php script inside the container is not triggered anymore. I believe it has to do with permission settings?
Upvotes: 1
Views: 112
Reputation: 36773
If you want the import
command to be executed by www-data inside the container, specify it to docker:
*/1 * * * * docker exec --user www-data apache_1 php /var/www/import
With what you've tried, the user www-data has not permissions to run docker commands. And, you have not such option to specify the username in crontab -e
(what you tried to do should be in /etc/crontab, or use su/sudo).
Upvotes: 1
Reputation: 1881
If your trying to run the command as the user while signed into the root user account your command should be:
su www-data; docker exec apache_1 php /var/www/import
Otherwise you need to switch to the www-data user(sudo su www-data) and then edit the cron jobs for the user(crontab -e). Each user has their own cronjobs.
Upvotes: 0