Docker 无法加载 sqlsrv php73 扩展
Docker with sqlsrv php73 extension failing to load
我制作了一个 docker LAMP 堆栈容器,包括 PHP7.3 和一些我需要 运行 我的 Web 应用程序的扩展。最近我需要包含 sqlsrv 扩展来建立与 MS SQL 服务器的连接,它运行良好了 1 天,当我重新启动我的 Docker 桌面时,它会自行重建,现在它不再工作了,即使我尝试删除容器的图像和卷并重建它。
当我 运行 docker-compose 时,我得到了这两个错误:
PHP Startup: Unable to load dynamic library 'pdo_sqlsrv.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20180731/pdo_sqlsrv.so (/usr/local/lib/php/extensions/no-debug-non-zts-20180731/pdo_sqlsrv.so: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20180731/pdo_sqlsrv.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20180731/pdo_sqlsrv.so.so: cannot open shared object file: No such file or directory))
PHP Startup: Unable to load dynamic library 'sqlsrv.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20180731/sqlsrv.so (/usr/local/lib/php/extensions/no-debug-non-zts-20180731/sqlsrv.so: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20180731/sqlsrv.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20180731/sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
这是我的配置文件:
docker-compose.yml
version: '3.8'
volumes:
datafiles:
services:
mysql:
image: mysql:8.0.0
container_name: mysql8
environment:
- MYSQL_ROOT_PASSWORD=x
- MYSQL_TCP_PORT=x
volumes:
- datafiles:/var/lib/mysql
- "./scripts:/docker-entrypoint-initdb.d"
restart: always
phpmyadmin:
container_name: phpmyadmin
image: phpmyadmin/phpmyadmin:latest
restart: always
environment:
PMA_HOST: x
PMA_USER: x
PMA_PASSWORD: x
ports:
- "8081:80"
website:
container_name: php73
build:
context: .
dockerfile: Dockerfile
image: rootkitty/lamp-quietal-webapp:latest
env_file:
- .env
ports:
- 80:80
- 443:443
depends_on:
- mysql
Docker文件COPYphp.ini允许添加
分机=sqlsrv.so
扩展名=pdo_sqlsrv.so
FROM php:7.3-apache
#Install git and MySQL extensions for PHP
ENV ACCEPT_EULA=Y
ENV MYSQL_DBHOST=x
ENV MYSQL_DBPORT=x
ENV MYSQL_DBUSER=x
ENV MYSQL_DBPASS=x
ENV MYSQL_DBNAME=x
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install apt-utils libxml2-dev gnupg apt-transport-https \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# Install git
RUN apt-get update \
&& apt-get -y install git \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# Install MS ODBC Driver for SQL Server
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update \
&& apt-get -y --no-install-recommends install msodbcsql17 unixodbc-dev \
&& pecl install sqlsrv \
&& pecl install pdo_sqlsrv \
&& echo "extension=pdo_sqlsrv.so" >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/30-pdo_sqlsrv.ini \
&& echo "extension=sqlsrv.so" >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/30-sqlsrv.ini \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
RUN apt-get update && \
apt-get install -y \
git libzip-dev \
&& docker-php-ext-install zip
RUN docker-php-ext-install intl mysqli pdo pdo_mysql
RUN a2enmod rewrite
COPY scripts/php.ini /usr/local/etc/php
COPY www /var/www/html/
EXPOSE 80/tcp
EXPOSE 443/tcp
我按照 Microsoft 官方文档编写了我的 Docker 文件 :
并在不同的 GitHub 页面上收集了一些代码。如何在我的 docker 容器上正确安装 sqlsrv?
所以,我的 Dockerfile 中有很多东西没有以正确的方式配置,这里是补丁:
FROM php:7.3-apache
# Env variables
ENV ACCEPT_EULA=y
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install apt-utils libxml2-dev gnupg apt-transport-https \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# Install git
RUN apt-get update \
&& apt-get -y install git \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
#Install ODBC Driver
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update
# Install sqlsrv
RUN apt-get update
RUN apt-get install -y wget
RUN wget http://ftp.br.debian.org/debian/pool/main/g/glibc/multiarch-support_2.24-11+deb9u4_amd64.deb && \
dpkg -i multiarch-support_2.24-11+deb9u4_amd64.deb
RUN apt-get -y install msodbcsql17 unixodbc-dev
RUN pecl install sqlsrv pdo_sqlsrv
# Install webapp extension
RUN apt-get update && \
apt-get install -y \
git libzip-dev libicu-dev\
&& docker-php-ext-install zip
RUN docker-php-ext-install intl mysqli pdo pdo_mysql
RUN a2enmod rewrite
COPY scripts/php.ini /usr/local/etc/php
COPY www /var/www/html/
EXPOSE 80/tcp
EXPOSE 443/tcp
事实上,我不得不安装 multiarch-support,尽管它是一个必需的软件包(如果它是一个?),但我仍然忽略了这个原因。然后,我必须首先安装我完全忘记的 ODBC 驱动程序。
现在看来一切正常
我制作了一个 docker LAMP 堆栈容器,包括 PHP7.3 和一些我需要 运行 我的 Web 应用程序的扩展。最近我需要包含 sqlsrv 扩展来建立与 MS SQL 服务器的连接,它运行良好了 1 天,当我重新启动我的 Docker 桌面时,它会自行重建,现在它不再工作了,即使我尝试删除容器的图像和卷并重建它。
当我 运行 docker-compose 时,我得到了这两个错误:
PHP Startup: Unable to load dynamic library 'pdo_sqlsrv.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20180731/pdo_sqlsrv.so (/usr/local/lib/php/extensions/no-debug-non-zts-20180731/pdo_sqlsrv.so: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20180731/pdo_sqlsrv.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20180731/pdo_sqlsrv.so.so: cannot open shared object file: No such file or directory))
PHP Startup: Unable to load dynamic library 'sqlsrv.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20180731/sqlsrv.so (/usr/local/lib/php/extensions/no-debug-non-zts-20180731/sqlsrv.so: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20180731/sqlsrv.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20180731/sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
这是我的配置文件:
docker-compose.yml
version: '3.8'
volumes:
datafiles:
services:
mysql:
image: mysql:8.0.0
container_name: mysql8
environment:
- MYSQL_ROOT_PASSWORD=x
- MYSQL_TCP_PORT=x
volumes:
- datafiles:/var/lib/mysql
- "./scripts:/docker-entrypoint-initdb.d"
restart: always
phpmyadmin:
container_name: phpmyadmin
image: phpmyadmin/phpmyadmin:latest
restart: always
environment:
PMA_HOST: x
PMA_USER: x
PMA_PASSWORD: x
ports:
- "8081:80"
website:
container_name: php73
build:
context: .
dockerfile: Dockerfile
image: rootkitty/lamp-quietal-webapp:latest
env_file:
- .env
ports:
- 80:80
- 443:443
depends_on:
- mysql
Docker文件COPYphp.ini允许添加
分机=sqlsrv.so
扩展名=pdo_sqlsrv.so
FROM php:7.3-apache
#Install git and MySQL extensions for PHP
ENV ACCEPT_EULA=Y
ENV MYSQL_DBHOST=x
ENV MYSQL_DBPORT=x
ENV MYSQL_DBUSER=x
ENV MYSQL_DBPASS=x
ENV MYSQL_DBNAME=x
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install apt-utils libxml2-dev gnupg apt-transport-https \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# Install git
RUN apt-get update \
&& apt-get -y install git \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# Install MS ODBC Driver for SQL Server
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update \
&& apt-get -y --no-install-recommends install msodbcsql17 unixodbc-dev \
&& pecl install sqlsrv \
&& pecl install pdo_sqlsrv \
&& echo "extension=pdo_sqlsrv.so" >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/30-pdo_sqlsrv.ini \
&& echo "extension=sqlsrv.so" >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/30-sqlsrv.ini \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
RUN apt-get update && \
apt-get install -y \
git libzip-dev \
&& docker-php-ext-install zip
RUN docker-php-ext-install intl mysqli pdo pdo_mysql
RUN a2enmod rewrite
COPY scripts/php.ini /usr/local/etc/php
COPY www /var/www/html/
EXPOSE 80/tcp
EXPOSE 443/tcp
我按照 Microsoft 官方文档编写了我的 Docker 文件 :
并在不同的 GitHub 页面上收集了一些代码。如何在我的 docker 容器上正确安装 sqlsrv?
所以,我的 Dockerfile 中有很多东西没有以正确的方式配置,这里是补丁:
FROM php:7.3-apache
# Env variables
ENV ACCEPT_EULA=y
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install apt-utils libxml2-dev gnupg apt-transport-https \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# Install git
RUN apt-get update \
&& apt-get -y install git \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
#Install ODBC Driver
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update
# Install sqlsrv
RUN apt-get update
RUN apt-get install -y wget
RUN wget http://ftp.br.debian.org/debian/pool/main/g/glibc/multiarch-support_2.24-11+deb9u4_amd64.deb && \
dpkg -i multiarch-support_2.24-11+deb9u4_amd64.deb
RUN apt-get -y install msodbcsql17 unixodbc-dev
RUN pecl install sqlsrv pdo_sqlsrv
# Install webapp extension
RUN apt-get update && \
apt-get install -y \
git libzip-dev libicu-dev\
&& docker-php-ext-install zip
RUN docker-php-ext-install intl mysqli pdo pdo_mysql
RUN a2enmod rewrite
COPY scripts/php.ini /usr/local/etc/php
COPY www /var/www/html/
EXPOSE 80/tcp
EXPOSE 443/tcp
事实上,我不得不安装 multiarch-support,尽管它是一个必需的软件包(如果它是一个?),但我仍然忽略了这个原因。然后,我必须首先安装我完全忘记的 ODBC 驱动程序。
现在看来一切正常