项目中需要使用到mssql,因此php需要开启sqlsrv,pdo_sqlsrv的扩展,并且需要安装ODBC驱动。搜索了一圈,整理出成功方案如下:
# PHP 容器配置 FROM suyar/php:8.2-integration # 构建生产/开发测试环境的镜像 ARG ENVIRONMENT # 替换系统镜像源,修改composer镜像源 RUN sed -i 's@/deb.debian.org/@/mirrors.tuna.tsinghua.edu.cn/@g' /etc/apt/sources.list.d/debian.sources && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ # 复制php配置文件 RUN if [ "$ENVIRONMENT" = "development" ] ; then \ mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" ; \ else \ mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" ; \ fi # 安装mssql驱动,procps RUN curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc RUN curl https://packages.microsoft.com/config/debian/12/prod.list | tee /etc/apt/sources.list.d/mssql-release.list RUN sed -i 's/ signed-by=\/usr\/share\/keyrings\/microsoft-prod.gpg//g' /etc/apt/sources.list.d/mssql-release.list RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql18 procps && apt-get upgrade -y && rm -rf /var/lib/apt/lists/* # 增加 odbc, pdo_odbc 扩展 RUN set -ex; \ docker-php-source extract; \ { \ echo '# https://github.com/docker-library/php/issues/103#issuecomment-271413933'; \ echo 'AC_DEFUN([PHP_ALWAYS_SHARED],[])dnl'; \ echo; \ cat /usr/src/php/ext/odbc/config.m4; \ } > temp.m4; \ mv temp.m4 /usr/src/php/ext/odbc/config.m4; \ apt-get update; \ apt-get install -y --no-install-recommends unixodbc-dev; \ rm -rf /var/lib/apt/lists/*; \ docker-php-ext-configure odbc --with-unixODBC=shared,/usr; \ docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr; \ docker-php-ext-install odbc pdo_odbc; \ docker-php-source delete RUN if [ "$ENVIRONMENT" = "development" ] ; then\ # 增加 sqlsrv, pdo_sqlsrv, xdebug 扩展 -- 用于开发,测试环境 pecl channel-update pecl.php.net && pecl install sqlsrv pdo_sqlsrv xdebug && docker-php-ext-enable sqlsrv pdo_sqlsrv xdebug ; \ else \ # 增加 sqlsrv, pdo_sqlsrv 扩展 -- 用于生产环境 pecl channel-update pecl.php.net && pecl install sqlsrv pdo_sqlsrv && docker-php-ext-enable sqlsrv pdo_sqlsrv ; \ fi # build 命令 # docker buildx build php:0.0.1 --build-arg="ENVIRONMENT=development" .
感谢 suyar 分享的基础镜像。另外整理过程中参考了很多大神的方案,但时间过久已经无法一一列出,感谢前辈们的分享。
标签:odbc,sqlsrv,apt,pdo,镜像,Docker,php,docker From: https://www.cnblogs.com/dust2/p/18215404