PHP8.1+Debian+SQL Server Docker镜像数据库连接问题求助
Debian+PHP8.1+SQL Server Docker镜像无法连接数据库
我在构建包含PHP8.1、Debian系统与SQL Server的Docker镜像时,遇到了数据库连接失败的问题。使用sqlcmd命令时需要手动修改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..
我刚接触相关技术,恳请各位提供帮助,以下是我编写的Dockerfile:
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
内容的提问来源于stack exchange,提问作者Ignacio Labra Garcia
相关产品推荐
相关产品推荐

