shinsenter/php

Autorun not working

Closed this issue · 6 comments

In the PHP images, the autoscript does not work, even when placed in the /startup/ folder.

ENV DISABLE_AUTORUN_SCRIPTS="false"

@devslimbr

I’m not sure which variant of the Docker images you’re using, but when the DISABLE_AUTORUN_SCRIPTS environment variable is set to anything other than an empty string or 0, autorun script execution will be disabled. You might want to try removing the line ENV DISABLE_AUTORUN_SCRIPTS=false and rebuilding your Docker container.

I hope this helps resolve your issue.

@devslimbr

By the way, let me confirm other two things:

  1. Do you see a greeting message when the container starts? If the message shows, it means that autorun is working.
  2. Has your script file in the /startup/ directory been given execute permissions (with chmod +x)?

For more details:
https://github.com/shinsenter/php?tab=readme-ov-file#usage-example

ARG  PHP_VERSION=8.0
FROM shinsenter/php:${PHP_VERSION}-fpm-nginx

ADD ./cronjobs/01-cron.sh /startup/01-cron.sh
RUN chmod +x /startup/01-cron.sh

ADD ./cronjobs/02-cron.sh /startup/02-cron.sh
RUN chmod +x /startup/02-cron.sh

RUN phpaddmod sockets

ENV TZ="America/Sao_Paulo"

ENV DOCUMENT_ROOT="/public"

ENV DISABLE_AUTORUN_GENERATING_INDEX="true"
ENV DISABLE_AUTORUN_COMPOSER_INSTALL="false"

ENV PHP_MEMORY_LIMIT="256M"
ENV PHP_POST_MAX_SIZE="100M"
ENV PHP_UPLOAD_MAX_FILE_SIZE="100M"
ENV ENABLE_CRONTAB="true"

version: '3'

services:
  api:
    build: .
    environment:
      TZ: America/Sao_Paulo
      APP_UID: 1000
      APP_GID: 1000
      APP_USER: developer
      APP_GROUP: developer
    container_name: api_base
    volumes:
      - ./:/var/www/html
    ports:
      - "8005:80"
    restart: always
    networks:
      - network_universal
      
networks:
  deploy-network:
  network_universal:
    external: true

"I did as you asked and removed the autorun context, but it still didn't work. The welcome message appears, but my scripts are not executed."

"In previous versions, the scripts ran normally.

The scripts already have permission both in the container and in the file itself, so when I enter the container, I'm able to execute them.

At the top of the welcome messages, this invalid user error appears, but I'm not sure if it's related, as the container runs normally."

chown: invalid user: 'developer:developer'

@devslimbr

Thanks for the detailed information.

I’m not sure what you wrote in the 01/02-cron.sh files or how you concluded that it wasn’t executed. You could try adding simple commands like echo Hello in the top of the 01/02-cron.sh scripts to see if the ‘Hello’ messages appear in the Docker logs. Also, since the greeting message is showing up, I believe your scripts were executed earlier (because, based on the file name order, your script 01/02-cron.sh would be executed before the container’s script 99-greeting).

I also think the autorun issue might be due to the chown error you mentioned. Could you try temporarily commenting out the two lines APP_USER and APP_GROUP in the docker-compose.yml file and then recreate the container to see if the autorun scripts work?

I did as requested, placing a simple echo script with execution permission. I disabled the developer user, and the error disappeared during startup, but the script did not execute at startup, even though the welcome screen was displayed.

If I revert to the image with the old tag from 5 months ago, now deprecated, it works

@devslimbr

Sorry for not being able to provide a definitive solution for your case.

Since Docker images prior to version 5.x (images with deprecated tags) are no longer receiving the latest security patches, I also don't recommend continuing to use them in the future.

Hopefully, newer Docker images will be able to address your issue someday, or perhaps you could share further insights into the issue you're facing.

Thank you for your understanding.