1

How do I add a PHP extention to an image? I am trying to build a LAMP docker with the PHP extension inotify tools

My file looks like the following - what is next to get inotify working?:

`

version: '24.0.5'
services:
    www:
        image: php:8.2.10-apache-bullseye
        volumes:
            - "./:/var/www/html"
        ports:
         - 80:80

`

I have Docker-Desktop with a Linux based LAMP image

I tried this dockerfile but exits 0

FROM php:8.0-apache
WORKDIR /var/www/html
COPY index.php index.php
RUN pecl install inotify
EXPOSE 80
3
  • Did you check "How to install more PHP extensions" in the Docker image page? Commented Sep 7, 2023 at 12:36
  • @ÁlvaroGonzález I have, but struggling to understand how to do that to an image eg php:8.2.10-apache-bullseye Commented Sep 7, 2023 at 17:15
  • I have just tried containerising php with pecl ext, but just exits 0 when launched - Clearly I am not undertsanding this yet. I rebuilt an image with php:apache but inotify is not an in built extension. So back to my question, can I somehow use pecl too add the ext to the php:8.2.10-apache-bullseye or am I fundamentally off target? Commented Sep 7, 2023 at 18:23

1 Answer 1

0

Oh my goodness! - Then I thought of ChatGPT

The solution

To create a Docker container for a LAMP (Linux, Apache, MySQL, PHP) server with the PHP extension inotify, you can follow these steps:

  1. Create a Dockerfile: Create a file named "Dockerfile" (no file extension) and add the following content:
# Use an official PHP image as the base image
FROM php:7.4-apache

# Install inotify extension
RUN pecl install inotify \
    && docker-php-ext-enable inotify

# Enable Apache modules and restart Apache
RUN a2enmod rewrite

# Copy your PHP application files to the container
COPY ./your-php-files /var/www/html/

# Expose port 80 for Apache
EXPOSE 80

# Start Apache in the foreground
CMD ["apache2-foreground"]

Replace ./your-php-files with the actual path to your PHP application files.

  1. Build the Docker image: Navigate to the directory containing the Dockerfile in your terminal and run:
docker build -t lamp-with-inotify .

This command will build the Docker image with the tag "lamp-with-inotify."

  1. Run the Docker container: Once the image is built, you can run a container from it using the following command:
docker run -d -p 8080:80 --name lamp-container lamp-with-inotify

This command will start a container named "lamp-container" and map port 8080 on your host to port 80 in the container.

  1. Access your LAMP server: You can access your LAMP server with the inotify extension by opening a web browser and navigating to http://localhost:8080 or http://<your-docker-host-ip>:8080.

Now you have a Docker container running a LAMP server with the PHP inotify extension. Make sure to adapt the PHP version and other configurations as needed for your specific application.

inotify

Sign up to request clarification or add additional context in comments.

1 Comment

ChatGPT answers are not allowed in this site because they're typically random text full of hard to spot factual errors. In any case, you kind of suggested that the official documentation to add pecl extensions is not clear/correct. Could you highlight what you did differently?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.