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.
PHP 8.4
PHP 8.3
PHP 8.2
PHP 8.1
namoshek/php-mssql:8.4-cli-alpine
namoshek/php-mssql:8.4-fpm-alpine
namoshek/php-mssql:8.3-cli-alpine
namoshek/php-mssql:8.3-fpm-alpine
namoshek/php-mssql:8.2-cli-alpine
namoshek/php-mssql:8.2-fpm-alpine
namoshek/php-mssql:8.1-cli-alpine
namoshek/php-mssql:8.1-fpm-alpine
What’s Included
Base System
Built on official PHP Alpine Docker images:
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.
Installation with Verification
# 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
CLI images include:
# Composer is pre-installed
composer --version
# Node.js with npm
node --version
npm --version
# Yarn package manager
yarn --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
FROM php:8.4-fpm-alpine
ENV ACCEPT_EULA=Y
# Install prerequisites required for tools and extensions
RUN apk add --update bash gnupg less libpng-dev libzip-dev su-exec unzip
# 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 pdo_sqlsrv redis sqlsrv zip
# 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.
Common 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
Docker Compose
Custom Dockerfile
docker run -it namoshek/php-mssql:8.4-cli-alpine php -v
Comparison with Debian
Feature Alpine Debian Base size Smaller (~50MB) Larger (~200MB) Total size ~250-300MB ~500-700MB C library musl libc glibc Package manager apk apt Compatibility Good Excellent Security Smaller attack surface More audit tooling Best for Production, size-critical Development, compatibility
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