docker-php-nginx icon indicating copy to clipboard operation
docker-php-nginx copied to clipboard

Update Dockerfile

Open sincze opened this issue 1 year ago • 1 comments

Added a few modules to make the image directly compatible with PDO DB Access. (Pretty common in PHP). Should not increase the size that much,.

apk add php83-pdo apk add php83-pdo_sqlite apk add php83-pdo_mysql

sincze avatar Aug 27 '24 18:08 sincze

Bump

sincze avatar Sep 19 '24 14:09 sincze

Hi @sincze ,

Thank you for your contribution. This request is coming along frequently, but this image is not meant as a all-in-one solution to run PHP projects. It's an example which you can copy/paste or use as base image and then extend it to your needs. I don't want to add extensions that are not part of the PHP core or bundled extensions.

If you want, you can add a document to the docs/ folder to describe how to do it. I'm happy to merge that.

TrafeX avatar Oct 20 '24 07:10 TrafeX

May I offer a suggestion to stay in line with your idea of keeping the image as pure as possible.

On first run of the docker have it check for a file called: FIRSTRUN.

first_run.sh

#!/bin/bash

# Check if the FIRSTRUN file exists
if [ ! -f /var/tmp/FIRSTRUN ]; then
  echo 'First run setup: installing additional packages and configurations...'

  # First run tasks go here, for example:
  apk add php83-pdo
  apk add php83-pdo_sqlite
  apk add php83-pdo_mysql

  # Create the FIRSTRUN file to mark the first run completion
  touch /var/tmp/FIRSTRUN
  echo 'First run complete. FIRSTRUN file created.'
else
  echo 'Not first run, skipping initialization tasks.'
fi

In we can solve it like this everyone is able to use the default docker as you created but can easily add the requested PHP packages without having to REBUILD the whole thing ;-)

Dockerfile

Copy the first run script

COPY first_run.sh /usr/local/bin/first_run.sh RUN chmod +x /usr/local/bin/first_run.sh

Dockerfile

Let the first run script execute before starting supervisord

CMD ["/bin/sh", "-c", "/usr/local/bin/first_run.sh && /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf"]

I hope I explained the idea well enough for it to be integrated ;-)

sincze avatar Oct 24 '24 15:10 sincze

Nice suggestion! But that would let you install system packages during runtime, when started the container. That's not what you want when you have a scalable environment and a few extra containers are spinned up. It will delay the start time, and introduces a risk that the installation fails or installs a different version than what you were expecting.

I would really recommend to build your own container. Copy/paste this example, or use it as base;

FROM trafex/php-nginx:latest

RUN apk add php83-pdo php83-pdo_sqlite php83-pdo_mysql

TrafeX avatar Oct 28 '24 21:10 TrafeX

ha you would think that ;-) It is an idea I got from Domoticz, it only runs the first time the docker starts. Only 1 delay

And it will start again when the docker is re-created (new version is pulled or docksr stop docker rm .... is used ). docker stop start does not cause the script to run again.

On Mon, Oct 28, 2024 at 10:29 PM Tim de Pater @.***> wrote:

Nice suggestion! But that would let you install system packages during runtime, when started the container. That's not what you want when you have a scalable environment and a few extra containers are spinned up. It will delay the start time, and introduces a risk that the installation fails or installs a different version than what you were expecting.

I would really recommend to build your own container. Copy/paste this example, or use it as base;

FROM trafex/php-nginx:latest

RUN apk add php83-pdo php83-pdo_sqlite php83-pdo_mysql

— Reply to this email directly, view it on GitHub https://github.com/TrafeX/docker-php-nginx/pull/185#issuecomment-2442668139, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMCHTO445LTV4PHCNGC2A3Z52NC5AVCNFSM6AAAAABNGWIQRWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINBSGY3DQMJTHE . You are receiving this because you were mentioned.Message ID: @.***>

sincze avatar Oct 28 '24 21:10 sincze