简体   繁体   English

创建一个包含 php、node.js 和 php 的 mysqli 的 Dockerfile

[英]Creating a Dockerfile that includes php, node.js, and php's mysqli

I am trying to create a Dockerfile that defines an environment with php, node.js with express and socket.io, and mysql interoperability.我正在尝试创建一个 Dockerfile,它使用 php、node.js 与 express 和 socket.io 以及 mysql 互操作性定义环境。

Currently I have this:目前我有这个:

FROM php:7.2-cli

RUN apt-get update && apt-get install -y nodejs npm
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN npm install
RUN npm install express
RUN npm install socket.io
EXPOSE 8080
CMD [ "node", "src/Server.js" ]

The problem is, when calling a php function that uses mysqli, I get this error:问题是,在调用使用 mysqli 的 php 函数时,出现此错误:

Fatal error: Uncaught Error: Class 'mysqli' not found in /usr/src/app/src/php/db_connect.php:21
Stack trace:
#0 /usr/src/app/src/php/websocketsAPI.php(11): include()
#1 {main}
  thrown in /usr/src/app/src/php/db_connect.php on line 21

I read this is due to a MySQL setting.我读到这是由于 MySQL 设置。 MySQL isn't installed on this container, so I thought that may be why.这个容器上没有安装 MySQL,所以我认为这可能是原因。 If I remember correctly, installing MySQL is not an process that can occur unattended, so I was reluctant to install MySQL using the normal apt-get system.如果我没记错的话,安装 MySQL 不是一个可以无人值守的过程,所以我不愿意使用普通的apt-get系统安装 MySQL。 I also read that mysqli is a php component.我还读到mysqli是一个 php 组件。 I don't need MySQL on this container, except perhaps to solve this current error.我不需要在这个容器上安装 MySQL,除非可能是为了解决这个当前的错误。 What is the best way to solve this?解决这个问题的最佳方法是什么?

I found the answer.我找到了答案。 I needed to add this line to the Dockerfile:我需要将此行添加到 Dockerfile:

RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli

That makes the Dockerfile this:这使得 Dockerfile 成为这样:

FROM php:7.2-cli

RUN apt-get update && apt-get install -y nodejs npm
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN npm install
RUN npm install express
RUN npm install socket.io
EXPOSE 8080
CMD [ "node", "src/Server.js" ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM