将 PHP 扩展 Inotify 添加到 docker-compose?

问题描述 投票:0回答:1

如何向图像添加 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
docker docker-compose dockerfile lamp inotify
1个回答
0
投票

天哪! - 然后我想到了ChatGPT

解决方案

要使用 PHP 扩展 inotify 为 LAMP(Linux、Apache、MySQL、PHP)服务器创建 Docker 容器,您可以按照以下步骤操作:

  1. 创建 Dockerfile: 创建一个名为“Dockerfile”(无文件扩展名)的文件并添加以下内容:
# 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 应用程序文件的实际路径。

  1. 构建 Docker 镜像: 导航到终端中包含 Dockerfile 的目录并运行:
docker build -t lamp-with-inotify .

此命令将构建带有标签“lamp-with-inotify”的 Docker 镜像。

  1. 运行 Docker 容器: 构建镜像后,您可以使用以下命令从中运行容器:
docker run -d -p 8080:80 --name lamp-container lamp-with-inotify

此命令将启动一个名为“lamp-container”的容器,并将主机上的端口 8080 映射到容器中的端口 80。

  1. 访问您的 LAMP 服务器: 您可以通过打开 Web 浏览器并导航到
    http://localhost:8080
    http://<your-docker-host-ip>:8080
    ,使用 inotify 扩展访问 LAMP 服务器。

现在您有了一个运行带有 PHP inotify 扩展的 LAMP 服务器的 Docker 容器。确保根据您的特定应用程序的需要调整 PHP 版本和其他配置。

© www.soinside.com 2019 - 2024. All rights reserved.