如何向图像添加 PHP 扩展?我正在尝试使用 PHP 扩展 inotify 工具构建一个 LAMP docker
我的文件如下所示 - 接下来要做什么才能让 inotify 工作?:
`
version: '24.0.5'
services:
www:
image: php:8.2.10-apache-bullseye
volumes:
- "./:/var/www/html"
ports:
- 80:80
`
我有 Docker-Desktop 和基于 Linux 的 LAMP 镜像
我尝试了这个 dockerfile 但退出 0
FROM php:8.0-apache
WORKDIR /var/www/html
COPY index.php index.php
RUN pecl install inotify
EXPOSE 80
天哪! - 然后我想到了ChatGPT
解决方案
要使用 PHP 扩展 inotify 为 LAMP(Linux、Apache、MySQL、PHP)服务器创建 Docker 容器,您可以按照以下步骤操作:
# 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"]
将
./your-php-files
替换为 PHP 应用程序文件的实际路径。
docker build -t lamp-with-inotify .
此命令将构建带有标签“lamp-with-inotify”的 Docker 镜像。
docker run -d -p 8080:80 --name lamp-container lamp-with-inotify
此命令将启动一个名为“lamp-container”的容器,并将主机上的端口 8080 映射到容器中的端口 80。
http://localhost:8080
或 http://<your-docker-host-ip>:8080
,使用 inotify 扩展访问 LAMP 服务器。现在您有了一个运行带有 PHP inotify 扩展的 LAMP 服务器的 Docker 容器。确保根据您的特定应用程序的需要调整 PHP 版本和其他配置。