Skip to main content

Overview

Alpine-based images are lightweight variants built on Alpine Linux, using musl libc instead of glibc. These images are optimized for production environments where image size and attack surface minimization are priorities.
Alpine images are significantly smaller than Debian variants (~50MB vs ~200MB base) while maintaining the same PHP and SQL Server functionality.

Available Tags

  • namoshek/php-mssql:8.4-cli-alpine
  • namoshek/php-mssql:8.4-fpm-alpine

What’s Included

Base System

Built on official PHP Alpine Docker images:
FROM php:8.4-cli-alpine

Microsoft SQL Server Components

All Alpine images include verified ODBC drivers and tools:
  • msodbcsql18 - Microsoft ODBC Driver 18 for SQL Server (18.4.1.1)
  • mssql-tools18 - Command-line tools including sqlcmd and bcp (18.4.1.1)
Microsoft packages are downloaded directly and GPG-verified before installation for security.
# Install MS SQL Server prerequisites with GPG verification
RUN curl -O https://download.microsoft.com/download/7/6/d/76de322a-d860-4894-9945-f0cc5d6a45f8/msodbcsql18_18.4.1.1-1_amd64.apk \
    && curl -O https://download.microsoft.com/download/7/6/d/76de322a-d860-4894-9945-f0cc5d6a45f8/mssql-tools18_18.4.1.1-1_amd64.apk \
    && curl -O https://download.microsoft.com/download/7/6/d/76de322a-d860-4894-9945-f0cc5d6a45f8/msodbcsql18_18.4.1.1-1_amd64.sig \
    && curl -O https://download.microsoft.com/download/7/6/d/76de322a-d860-4894-9945-f0cc5d6a45f8/mssql-tools18_18.4.1.1-1_amd64.sig \
    && curl https://packages.microsoft.com/keys/microsoft.asc | gpg --import - \
    && gpg --verify msodbcsql18_18.4.1.1-1_amd64.sig msodbcsql18_18.4.1.1-1_amd64.apk \
    && gpg --verify mssql-tools18_18.4.1.1-1_amd64.sig mssql-tools18_18.4.1.1-1_amd64.apk \
    && apk add --allow-untrusted msodbcsql18_18.4.1.1-1_amd64.apk mssql-tools18_18.4.1.1-1_amd64.apk \
    && rm *.apk *.sig

PHP Extensions

Identical extension set to Debian images:

bcmath

Arbitrary precision mathematics

ds

Efficient data structures

exif

Read EXIF metadata from images

gd

Image processing library

intl

Internationalization functions

opcache

Opcode caching for performance

pcntl

Process control functions

pcov

Code coverage driver (CLI only)

pdo_sqlsrv

PDO driver for SQL Server

redis

Redis client extension

sqlsrv

Native SQL Server driver

zip

ZIP archive handling

Development Tools (CLI Images Only)

CLI images include:
# Composer is pre-installed
composer --version

Alpine System Utilities

Minimal but essential utilities:
  • bash - Bourne Again Shell
  • gnupg - Package verification
  • less - File pager
  • nano - Text editor (CLI only)
  • su-exec - Execute commands as another user
  • unzip - Archive extraction

Complete Dockerfile

FROM php:8.4-cli-alpine

ENV ACCEPT_EULA=Y

# Install prerequisites required for tools and extensions
RUN apk add --update bash gnupg less libpng-dev libzip-dev nano nodejs npm su-exec unzip

# Install yarn as global npm package
RUN npm install -g yarn

# Install prerequisites for the sqlsrv and pdo_sqlsrv PHP extensions
RUN curl -O https://download.microsoft.com/download/7/6/d/76de322a-d860-4894-9945-f0cc5d6a45f8/msodbcsql18_18.4.1.1-1_amd64.apk \
    && curl -O https://download.microsoft.com/download/7/6/d/76de322a-d860-4894-9945-f0cc5d6a45f8/mssql-tools18_18.4.1.1-1_amd64.apk \
    && curl -O https://download.microsoft.com/download/7/6/d/76de322a-d860-4894-9945-f0cc5d6a45f8/msodbcsql18_18.4.1.1-1_amd64.sig \
    && curl -O https://download.microsoft.com/download/7/6/d/76de322a-d860-4894-9945-f0cc5d6a45f8/mssql-tools18_18.4.1.1-1_amd64.sig \
    && curl https://packages.microsoft.com/keys/microsoft.asc | gpg --import - \
    && gpg --verify msodbcsql18_18.4.1.1-1_amd64.sig msodbcsql18_18.4.1.1-1_amd64.apk \
    && gpg --verify mssql-tools18_18.4.1.1-1_amd64.sig mssql-tools18_18.4.1.1-1_amd64.apk \
    && apk add --allow-untrusted msodbcsql18_18.4.1.1-1_amd64.apk mssql-tools18_18.4.1.1-1_amd64.apk \
    && rm *.apk *.sig

# Retrieve the script used to install PHP extensions
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/install-php-extensions

# Install required PHP extensions
RUN chmod uga+x /usr/bin/install-php-extensions \
    && sync \
    && install-php-extensions bcmath ds exif gd intl opcache pcntl pcov pdo_sqlsrv redis sqlsrv zip

# Download composer and mark it as executable
RUN curl -o /usr/local/bin/composer https://getcomposer.org/composer-stable.phar \
    && chmod +x /usr/local/bin/composer

# Set the working directory
WORKDIR /var/www

Image Size

Alpine images are significantly smaller:
  • CLI images: ~250-300 MB
  • FPM images: ~200-250 MB
Alpine images are 50-60% smaller than Debian equivalents, resulting in faster pulls and reduced storage costs.

When to Use Alpine Images

Production

Ideal for production deployments prioritizing minimal size and attack surface

Container Orchestration

Perfect for Kubernetes, Docker Swarm, and other orchestration platforms

CI/CD

Faster build and deployment times due to smaller image size

Cost Optimization

Reduced storage and bandwidth costs in cloud environments

Considerations

musl vs glibc: Alpine uses musl libc instead of glibc. While most PHP applications work perfectly, some binary extensions or compiled dependencies may have compatibility issues.
  • Binary extensions compiled for glibc may not work
  • Some NodeJS native modules might need recompilation
  • DNS resolution behavior differs slightly from glibc systems
  • Certain C libraries may need Alpine-specific versions
  • Most PHP packages work without modification
  • Use Alpine-native packages when available
  • Compile extensions from source if needed
  • Test thoroughly before deploying to production
  • Switch to Debian images if compatibility issues arise

Usage Examples

docker run -it namoshek/php-mssql:8.4-cli-alpine php -v

Comparison with Debian

FeatureAlpineDebian
Base sizeSmaller (~50MB)Larger (~200MB)
Total size~250-300MB~500-700MB
C librarymusl libcglibc
Package managerapkapt
CompatibilityGoodExcellent
SecuritySmaller attack surfaceMore audit tooling
Best forProduction, size-criticalDevelopment, compatibility

Performance Characteristics

Startup Time

Faster container startup due to smaller image size

Memory Usage

Lower baseline memory footprint

Network Transfer

Reduced bandwidth usage for image pulls

Runtime Performance

Equivalent PHP performance to Debian images

Next Steps

Debian Images

Explore full-featured Debian variants

Swoole Images

Add high-performance async capabilities

Configuration

Configure PHP settings and extensions

MS SQL Connection

Connect to SQL Server databases

Build docs developers (and LLMs) love