Unable to install sqlsrv and pdo_sqlsrv using Docker PHP 8 Apache

Im relatively new into docker and my case is I want to try serving my php website that have configuration to connect into SQL Server, fetching data from server into localhost. my directory is like this:


and here is my configured docker-compose.yaml and Dockerfile


FROM php:8.0-apache
# Change default Apache port from 80 into 81
RUN sed -i 's/Listen 80/Listen 81/' /etc/apache2/ports.conf
# Connect Apache with port 81
RUN sed -i 's/:80/:81/' /etc/apache2/sites-available/000-default.conf


# 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 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/11/prod.list > /etc/apt/sources.list.d/mssql-release.list \
    && apt-get update \
    && apt-get -y --no-install-recommends install msodbcsql18 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/*

# Install required extensions
RUN docker-php-ext-install intl mysqli pdo pdo_mysql
RUN a2enmod rewrite
WORKDIR /var/www/html/
COPY ./src /var/www/html/

# Expose port 81
CMD ["apache2-foreground"]


version: '3'

      context: .
      dockerfile: Dockerfile
    container_name: php-apache
      - "81:81"
      - ./src:/var/www/html
    restart: unless-stopped

this successfully run during ‘docker compose build’ and ‘docker compose up’ but when I check the extension installed in localhost:81/info.php, there’s no sqlsrv or pdo_sqlsrv installed. is there something missing or something i need to include for my Dockerfile or docker-compose.yaml?

I would say your complex setup process is not working. Not sure where it is coming from. But this does not seem like a Docker issue.

hmm okay… after more reading i found this regarding a similar case to add a sqlsrv and pdo_sqlsrv in php 7.4. I gonna try to modify using the dockerfile in this case first since it has a successful respond