I am trying to create a Dockerfile that defines an environment with php, node.js with express and socket.io, and mysql interoperability.
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:
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 isn't installed on this container, so I thought that may be why. 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. I also read that mysqli
is a php component. I don't need MySQL on this container, except perhaps to solve this current error. What is the best way to solve this?
I found the answer. I needed to add this line to the Dockerfile:
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
That makes the Dockerfile 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 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" ]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.