skip to Main Content

Background: I’m very new to Docker and working with a team on a CodeIgniter application. The current version of the project is running in a Docker container using MySQL, but we are exploring moving to SQL Server.

When I run docker build --no-cache . everything seems to work with no errors, and I can connect to the database using HeidiSQL.

However, when I open the application in a browser, I get the:

Call to undefined function sqlsrv_connect()

error and if I pull up my test file with phpinfo() I do not see sqlsrv or pdo_sqlsrv anywhere.

I’ve done a lot of research online, sought help from team mates (all of us are Docker newbs), and even purchased and gone through tutorials but I haven’t been able to solve the problem. Any help would be greatly appreciated, as I feel like I’m just overlooking something obvious.

Below are my docker-compose.yaml and Dockerfile. In the Dockerfile you can see 4 variations I’ve found online to try to get this working, but all of them have the same result.

docker-compose.yaml

version: "3.1"
services:
    db_mssql:
        container_name: db_mssql
        image: mcr.microsoft.com/mssql/server:2019-CU12-ubuntu-20.04
        environment:
            ACCEPT_EULA: "Y"
            SA_PASSWORD: "Testing123"
            MSSQL_PID: "Developer"
        ports:
            - '1433:1433'
        volumes: 
            - mssql-volume:/var/opt/mssql

    app-cp-v3:
        build: .
        container_name: app-cp-v3
        ports:
            - 8090:80
        volumes:
            - ./app-cp-v3/:/var/www/html
        networks:
            - default
        working_dir: /var/www/html
        environment:
            XDEBUG_ENABLE: "true"
            XDEBUG_CONFIG: "remote_enable=1 remote_mode=req remote_host=docker.for.mac.localhost remote_port=9004 remote_autostart=1"

volumes:
    mssql-volume:

Dockerfile

FROM php:7.3-apache

ENV ACCEPT_EULA=Y

RUN a2enmod rewrite

RUN sed -ri -e 's!/var/www/html!/var/www/html/public/html!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!/var/www/html/public/html!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

RUN apt-get update && apt-get install -y nano wget gnupg2

RUN docker-php-ext-install bcmath sockets pcntl 

RUN pecl install xdebug-2.9.7
RUN docker-php-ext-enable xdebug 
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 
&& echo "xdebug.remote_autostart=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 
&& echo "xdebug.remote_port=9001" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 
&& echo "xdebug.remote_handler=dbgp" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 
&& echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 
&& echo "xdebug.idekey=vscode" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 
&& echo "xdebug.remote_host=docker.for.mac.localhost" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
#RUN echo "xdebug.remote_enable=1" >> /usr/local/etc/php/php.ini

RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 
RUN curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list 
RUN apt-get update 
RUN ACCEPT_EULA=Y apt-get -y --no-install-recommends install msodbcsql17 unixodbc-dev 
RUN pecl install sqlsrv
RUN pecl install pdo_sqlsrv
RUN docker-php-ext-enable sqlsrv pdo_sqlsrv

# V1
# Install MS ODBC Driver for SQL Server
#ENV ACCEPT_EULA=Y
#RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 
#    && curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list 
#    && apt-get update 
#    && ACCEPT_EULA=Y 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/*
#
# END V1

# V2
#
#ENV ACCEPT_EULA=Y
#RUN apt-get update 
#    && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 
#    && curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list 
#        > /etc/apt/sources.list.d/mssql-release.list 
#    && apt-get install -y --no-install-recommends 
#        locales 
#        apt-transport-https 
#    && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen 
#    && locale-gen 
#    && apt-get update 
#    && apt-get -y --no-install-recommends install 
#        unixodbc-dev 
#        msodbcsql17
#
#RUN pecl install sqlsrv pdo_sqlsrv 
#    && docker-php-ext-enable sqlsrv pdo_sqlsrv
#
# END V2

# V3
#
#RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
#
#Download appropriate package for the OS version
#RUN curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
#RUN apt-get update
#RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17
# optional: for unixODBC development headers
#RUN apt-get install -y unixodbc-dev
#
# activate extensions in php.ini
#RUN pecl channel-update pecl.php.net 
#    && pecl install sqlsrv pdo_sqlsrv 
#    && docker-php-ext-enable sqlsrv pdo_sqlsrv
#
# END V3

# V4
#
# Microsoft SQL Server Prerequisites
#RUN apt-get update > /dev/null 
#    && apt-get install -y --no-install-recommends gnupg2 > /dev/null 
#    && apt-get update > /dev/null 
#    && 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 install -y --no-install-recommends 
#        locales 
#        apt-transport-https 
#        > /dev/null 
#    && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen 
#    && locale-gen > /dev/null 
#    && apt-get update > /dev/null 
#    && apt-get -y --no-install-recommends install 
#        unixodbc-dev 
#        msodbcsql17 
#        > /dev/null 
#    
# Install & enable Microsoft SQL Server
#RUN docker-php-ext-install pdo > /dev/null 
#    && pecl install sqlsrv pdo_sqlsrv > /dev/null 
#    && docker-php-ext-enable sqlsrv pdo_sqlsrv > /dev/null 
#
#
# END V4

RUN curl -sS https://getcomposer.org/installer -o composer-setup.php
RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer

2

Answers


  1. Chosen as BEST ANSWER

    Thanks for the response. I figured this out on my own eventually, but the issue was exactly as ddegasperi suggested. I was re-using the old image rather than the newly built one.


  2. Can you try to run docker-compose build app-cp-v3 instead of docker build.

    When you use docker-compose with build instructions, it creates a docker image with its own name (a combination of folder name + service). This means if you use docker build without correct tag docker-compose uses the "old" image.

    When you work with docker-compose my advice is to use also the docker-compose cli (for builds, pulls, etc.) over the docker cli to avoid such pitfalls.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search