skip to Main Content

I have a PHP:8.1 Docker container that has always worked, and 1 week ago without modifying anything and trying to rebuild the image the instruction "pecl install sqlsrv" stopped working. Give error. If I make an error in this part of the code, the container is created normally.

Important! I tried to use a pure Debian docker image (only test), with nothing, nothing even the basics of Linux had, I installed everything by hand, when I tried to install sqlsrv and it gave the same error. So I don’t think it’s docker:php:8.1. I also tried with php:7.4 and earlier versions.

The log is very big but I’ll put the final part that shows more information and the error:

...log...log...more log...p/ext/date/lib -I/tmp/pear/temp/sqlsrv/shared/  -DHAVE_CONFIG_H  -g -O2    -o sqlsrv.la -export-dynamic -avoid-version -prefer-pic -module -rpath /tmp/pear/temp/pear-build-defaultuserfcT8aJ/sqlsrv-5.10.1/modules  conn.lo util.lo init.lo stmt.lo shared/core_conn.lo shared/core_results.lo shared/core_stream.lo shared/core_init.lo shared/core_stmt.lo shared/core_util.lo shared/FormattedPrint.lo shared/localizationimpl.lo shared/StringFunctions.lo -Wl,-z,now -lstdc++ -lodbc -lodbcinst
libtool: link: warning: library `/usr/lib/x86_64-linux-gnu/libodbc.la' was moved.
grep: /usr/lib/x86_64-linux-gnu/libltdl.la: No such file or directory
/bin/sed: can't read /usr/lib/x86_64-linux-gnu/libltdl.la: No such file or directory
libtool: link: `/usr/lib/x86_64-linux-gnu/libltdl.la' is not a valid libtool archive
make: *** [Makefile:249: sqlsrv.la] Error 1
ERROR: `make' failed

Esse é meu arquivo dockerfile:

FROM php:8.1

# Get latest Composer
# COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Install dependecies
RUN apt-get update --fix-missing 
  && apt-get -y install cron git libicu-dev libonig-dev libzip-dev gnupg 
  unzip locales libpng-dev libxml2-dev nano wget software-properties-common supervisor

# Install Java 8
RUN mkdir -p /usr/share/man/man1 
  && wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | apt-key add - 
  && add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/ 
  && apt-get update && apt-get -y install adoptopenjdk-8-hotspot

# ...
RUN apt-get clean 
  && rm -rf /var/lib/apt/lists/* 
  && locale-gen en_US.UTF-8 
  && localedef -f UTF-8 -i en_US en_US.UTF-8 
  && mkdir /var/run/php-fpm

# Install SqlServer PHP driver
RUN cat /etc/os-release 
  && apt-get update 
  && 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 install -y --no-install-recommends apt-transport-https 
  && apt-get update 
  && ACCEPT_EULA=Y apt-get -y --no-install-recommends install  unixodbc-dev msodbcsql17

# Install PHP extensions
RUN docker-php-ext-install intl pdo_mysql zip bcmath mbstring exif pcntl bcmath gd 
  && pecl install sqlsrv pdo_sqlsrv 
  && docker-php-ext-enable sqlsrv pdo_sqlsrv

# App code location
WORKDIR /app

# Copy project files
COPY ./app/backend/smartsell-3-backend /app

# Copy crontab config file (To automatically run Laravel schedule/tasks)
RUN rm /etc/crontab 
  && cp /app/docker/crontab /etc/cron.d/fastmanager 
  && cp /app/docker/crontab /etc

# Copy supervisor config file (To automatically process Laravel jobs)
RUN cat /app/supervisord.conf > /etc/supervisor/supervisord.conf

# Install project dependencies
RUN composer install

# Expose container port
EXPOSE 8000

# Run server
CMD chmod 777 /app/entrypoint.sh; 
  /app/entrypoint.sh; 
  php artisan serve --host=0.0.0.0 --port=8000

2

Answers


  1. Chosen as BEST ANSWER

    In my case, it was an error in the Microsoft repository, I found it in a recent forum talking about this bug. Alternatively install SQL from the Ubuntu repository (the image remains Debian).

    So what changed was this:

    # Install SqlServer PHP driver
    RUN cat /etc/os-release 
      && apt-get update 
      && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 
      && curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list 
          > /etc/apt/sources.list.d/mssql-release.list 
      && apt-get install -y --no-install-recommends apt-transport-https 
      && apt-get update 
      && ACCEPT_EULA=Y apt-get -y --no-install-recommends install unixodbc-dev msodbcsql17
    

  2. Both unixodbc and unixodbc-dev must be installed.

    # SQL Server
    RUN wget https://packages.microsoft.com/keys/microsoft.asc && 
        apt-key add microsoft.asc && 
        curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list && 
        apt-get update && 
        ACCEPT_EULA=Y apt-get install -y --no-install-recommends 
        unixodbc 
        unixodbc-dev 
        msodbcsql17 
        mssql-tools17
    
    

    An alternative way is installing ODBC Driver from the source with ltdl enabled:

    # UnixODBC
    RUN wget ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.11.tar.gz && 
        tar -xzf unixODBC-2.3.11.tar.gz && 
        cd unixODBC-2.3.11 && 
        ./configure --enable-ltdl-install --prefix=/usr/local/unixODBC && 
        make && 
        make install
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search