DockerFile PHP8.1 Debian SQL Server

问题描述 投票:0回答:1

我的 DockerFile 遇到了一些问题,我必须使用 php8.1、Linux 和 SQL Server 创建一个 docker 映像。 我制作了以下 Docker,但我无法连接到我的数据库,例如,如果我想使用

slqcmd
命令,我必须编辑 bash,然后如果尝试连接不起作用,只需给出我这个错误

Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to 3332a686a938. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

我刚刚开始,所以欢迎任何帮助

FROM debian:11

ENV DEBIAN_FRONTEND noninteractive

# ESTABLECER ZONA HORARIA
ENV     TZ=America/Santiago
RUN     ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

#Install update
RUN apt-get update
RUN apt-get upgrade -y

#Install facilitators
RUN apt-get -y install locate mlocate wget apt-utils curl apt-transport-https lsb-release \
             ca-certificates software-properties-common zip unzip vim rpl sendmail

ENV     PHP_MAX_SIZE="50M"

# Fix ‘add-apt-repository command not found’
RUN apt-get install software-properties-common

RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list

#Install update
RUN apt-get update

# Set Timezone
RUN ln -fs /usr/share/zoneinfo/${TZ} /etc/localtime \
    && apt-get update \
    && apt-get install -y --no-install-recommends tzdata \
    && dpkg-reconfigure --frontend noninteractive tzdata

#intall Apache + PHP
RUN apt-get -y install apache2 libapache2-mod-php8.1 php8.1 php8.1-cli php8.1-common php8.1-opcache

#OpenSsl
RUN     apt-get update && \ 
    apt-get install -y libssl-dev

#PHP Install CURl
RUN apt-get -y install curl php8.1-curl

#PHP Intall DOM, Json, XML e Zip
RUN apt-get -y install php8.1-dom php8.1-xml php8.1-zip php8.1-soap php8.1-intl php8.1-xsl

#PHP Install MbString
RUN apt-get -y install php8.1-mbstring

#PHP Install GD
RUN apt-get -y install php8.1-gd

#PHP Install PDO SqLite
RUN apt-get -y install php8.1-pdo php8.1-pdo-sqlite php8.1-sqlite3

#PHP Install PDO MySQL
RUN apt-get -y install php8.1-pdo php8.1-pdo-mysql php8.1-mysql 

#PHP Install PDO PostGress
RUN apt-get -y install php8.1-pdo php8.1-pgsql

## -------- Config Apache ----------------
RUN a2dismod mpm_event
RUN a2dismod mpm_worker
RUN a2enmod  mpm_prefork
RUN a2enmod  rewrite
RUN a2enmod  php8.1

# Enable .htaccess reading
RUN LANG="en_US.UTF-8" rpl "AllowOverride None" "AllowOverride All" /etc/apache2/apache2.conf

## ------------- LDAP ------------------
#PHP Install LDAP
RUN apt-get -y install php8.1-ldap

#Apache2 enebla LDAP
RUN a2enmod authnz_ldap
RUN a2enmod ldap

## ------------- Add-ons ------------------
#Install GIT
RUN apt-get -y install -y git-core

#PHP Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

#PHP Install PHPUnit
#https://phpunit.  de/announcements/phpunit-9.html
RUN wget -O /usr/local/bin/phpunit-9.phar https://phar.phpunit.de/phpunit-9.phar; chmod +x /usr/local/bin/phpunit-9.phar; \
ln -s /usr/local/bin/phpunit-9.phar /usr/local/bin/phpunit

RUN apt-get -y install php8.1-dev php8.1-xml php8.1-intl

ENV ACCEPT_EULA=Y

RUN curl -s  https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
    && curl -s  https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list

RUN apt-get update

RUN apt-get install -y --no-install-recommends \
        locales \
        apt-transport-https \
    && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
    && locale-gen

# install MS ODBC 18
RUN apt-get -y install msodbcsql18 mssql-tools18

RUN echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bash_profile
RUN echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
RUN exec bash

RUN apt-get install -y --allow-downgrades odbcinst=2.3.7 odbcinst1debian2=2.3.7 unixodbc=2.3.7 unixodbc-dev=2.3.7

#RUN apt-get -y install unixodbc unixodbc-dev
RUN apt-get -y install gcc g++ make autoconf libc-dev pkg-config

##------------ Install Drive 5.10.1 for SQL Server -----------
RUN apt-get install php-pear
RUN pecl -vvv install sqlsrv-5.10.1
RUN pecl -vvv install pdo_sqlsrv-5.10.1

#instalacion de nano
RUN apt-get install nano

#For PHP CLI
RUN echo extension=pdo_sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/30-pdo_sqlsrv.ini
RUN echo extension=sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/20-sqlsrv.ini

#For PHP WEB
RUN echo "extension=pdo_sqlsrv.so" >> /etc/php/8.1/apache2/conf.d/30-pdo_sqlsrv.ini
RUN echo "extension=sqlsrv.so" >> /etc/php/8.1/apache2/conf.d/20-sqlsrv.ini

#Config Apache
RUN a2dismod mpm_event
RUN a2enmod mpm_prefork
RUN a2enmod php8.1

## ------------- Finishing ------------------
RUN apt-get clean

#Creating index of files
RUN updatedb

EXPOSE 80
EXPOSE 443
CMD apachectl -D FOREGROUND

php sql-server dockerfile debian
1个回答
0
投票

好吧,我终于找到了解决方案,只是一个修复,openssl.cnf 与 sql server 所需的许可不匹配,所以…我在 php 查询中添加了“TrustServerCertificate” => true,它可以工作 如果我在连接设置末尾放入控制台 -C 也是一样的,如下所示:

./sqlcmd -S host -U user -P password -d database -C
© www.soinside.com 2019 - 2024. All rights reserved.