【问题标题】:Dockerfile to start PHP Container with mysqli and a2enmod rewrite not working使用 mysqli 和 a2enmod 重写启动 PHP 容器的 Dockerfile 不起作用
【发布时间】:2018-09-15 13:55:33
【问题描述】:

我正在尝试基于 dockerfile 启动容器。它应该有 mysqli 和 a2enmod。

我的 Dockerfile 是

FROM php:7.1-apache
RUN docker-php-ext-install mysqli && a2enmod rewrite && service apache2 restart

但是 a2enmod 在开始之前没有启用。当我附加到容器 bash 时,我发现 a2enmod 没有启用

$ a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run: service apache2 restart
$ a2enmod rewrite
Module rewrite already enabled

我做错了什么?

【问题讨论】:

  • 也许指定 a2enmod 脚本的完整路径。
  • 它接缝表明该模块在容器中默认未启用。容器是在启动时从映像构建的。我对码头工人不是很熟悉。看来您需要学习如何更改 docker 映像。 (图像就像容器实例的模板。)
  • 你重建你的 docker 镜像了吗?你如何运行容器?为什么要在 Dockerfile 中运行 service apache2 restart
  • @AlexKarshin 启用模块后需要重新启动 apache2。我猜 docker 文件中的命令在不可用的情况下在某个太早的状态下执行。
  • @Quasimodo'sclone 请阅读 Docker 的工作原理。我知道需要重启 apache,但 apache 是在容器中运行,而不是在构建期间运行:-/

标签: php apache docker


【解决方案1】:

正如Alex Karshin 所建议的,有两个问题。

  1. 我需要重建 docker 映像。
  2. 我不需要重新启动 apache 服务,因为 apache 在容器初始化期间没有运行。

解决这些问题解决了我的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-27
    • 2017-10-20
    相关资源
    最近更新 更多