wodby / php

Generic PHP docker container images
MIT License
152 stars 103 forks source link

Run cron with user 1000 #90

Open trebormc opened 4 years ago

trebormc commented 4 years ago

My problem is that I need to run the Drupal cron for some websites on the development servers (run periodic imports or reindex the search_api for example).

I have tried to execute the cron in several ways, but I always end up getting the same fault. After researching a few hours, I have seen that people who use Alpine say they use the root user (which I don't think is the best idea)

I have seen that you delete the root crontab, and only leave the user www-data. I think the problem comes from here, since drush should always be run as user 1000 (wodby), right? https://github.com/wodby/php/blob/2408549b2bde7574be8e8982882b5b4a6e7d8116/7/Dockerfile#L301

A possible solution would be to have both volumes:

My docker-compose:

    image: wodby/drupal-php:$PHP_TAG
    container_name: "${PROJECT_NAME}_crond"
    command: sudo -E LD_PRELOAD=/usr/lib/preloadable_libiconv.so crond -f -d 0
    volumes:
      - ./app:/var/www/html
      - ./files:/mnt/files
      - ./crontab:/etc/crontabs/www-data

My crontab:

    image: wodby/drupal-php:$PHP_TAG
    container_name: "${PROJECT_NAME}_crond"
    restart: always
    command: sudo -E LD_PRELOAD=/usr/lib/preloadable_libiconv.so crond -f -d 0
    volumes:
      - ./app:/var/www/html
      - ./files:/mnt/files
      - ./crontab:/etc/crontabs/www-data

I just want to have the cron running, and I'm starting with docker, maybe I'm wrong with the reason why it doesn't work. Any other idea?