|
| 1 | +# From Alpine to Debian: Migration Guide |
| 2 | + |
| 3 | +This document outlines the key differences between the Alpine and Debian variants of the kooldev/php Docker images. |
| 4 | + |
| 5 | +## Quick Comparison |
| 6 | + |
| 7 | +| Feature | Alpine | Debian | |
| 8 | +|---------|--------|--------| |
| 9 | +| Base Image | `php:8.x-fpm-alpine` | `php:8.x-fpm` (Debian) | |
| 10 | +| Image Size | Smaller (~150MB) | Larger (~400MB) | |
| 11 | +| Package Manager | `apk` | `apt-get` | |
| 12 | +| Shell | `sh` (BusyBox) | `bash` | |
| 13 | +| Privilege Drop | `su-exec` | `gosu` | |
| 14 | +| Supervisord | ochinchina/supervisord (Go static binary) | Official supervisor package (Python) | |
| 15 | +| Architecture | amd64 only (nginx variants) | amd64 + arm64 | |
| 16 | +| glibc | musl libc | glibc | |
| 17 | + |
| 18 | +## When to Use Debian |
| 19 | + |
| 20 | +Choose the Debian variant when: |
| 21 | + |
| 22 | +- **ARM64/Apple Silicon support is needed** - The Debian variant has native multi-arch support |
| 23 | +- **Compatibility issues with Alpine** - Some PHP extensions or native libraries may have issues with musl libc |
| 24 | +- **Debugging needs** - Debian includes more debugging tools out of the box |
| 25 | +- **Familiarity** - Teams more familiar with Debian/Ubuntu environments |
| 26 | + |
| 27 | +## When to Use Alpine |
| 28 | + |
| 29 | +Choose the Alpine variant when: |
| 30 | + |
| 31 | +- **Minimal image size is critical** - Alpine images are significantly smaller |
| 32 | +- **Security through minimalism** - Smaller attack surface with fewer packages |
| 33 | +- **amd64-only deployments** - No need for ARM64 support |
| 34 | + |
| 35 | +## Key Differences in Detail |
| 36 | + |
| 37 | +### 1. Supervisord Implementation |
| 38 | + |
| 39 | +**Alpine** uses [ochinchina/supervisord](https://github.com/ochinchina/supervisord), a Go-based reimplementation: |
| 40 | + |
| 41 | +```ini |
| 42 | +# Alpine supervisor.conf |
| 43 | +[program:nginx] |
| 44 | +depends_on = php-fpm |
| 45 | +command = nginx -g "daemon off;" |
| 46 | +stopasgroup = true |
| 47 | +stderr_logfile = /dev/stderr |
| 48 | +stdout_logfile = /dev/stdout |
| 49 | + |
| 50 | +[program:php-fpm] |
| 51 | +command = php-fpm |
| 52 | +stopasgroup = true |
| 53 | +stderr_logfile = /dev/stderr |
| 54 | +stdout_logfile = /dev/stdout |
| 55 | +``` |
| 56 | + |
| 57 | +**Debian** uses the official Python-based supervisord package: |
| 58 | + |
| 59 | +```ini |
| 60 | +# Debian supervisor.conf |
| 61 | +[supervisord] |
| 62 | +nodaemon=true |
| 63 | +user=root |
| 64 | +logfile=/dev/null |
| 65 | +logfile_maxbytes=0 |
| 66 | +pidfile=/run/supervisord.pid |
| 67 | + |
| 68 | +[program:php-fpm] |
| 69 | +command=php-fpm |
| 70 | +priority=10 |
| 71 | +autostart=true |
| 72 | +autorestart=true |
| 73 | +stopasgroup=true |
| 74 | +killasgroup=true |
| 75 | +stdout_logfile=/dev/stdout |
| 76 | +stdout_logfile_maxbytes=0 |
| 77 | +stderr_logfile=/dev/stderr |
| 78 | +stderr_logfile_maxbytes=0 |
| 79 | + |
| 80 | +[program:nginx] |
| 81 | +command=nginx -g "daemon off;" |
| 82 | +priority=20 |
| 83 | +autostart=true |
| 84 | +autorestart=true |
| 85 | +stopasgroup=true |
| 86 | +killasgroup=true |
| 87 | +stdout_logfile=/dev/stdout |
| 88 | +stdout_logfile_maxbytes=0 |
| 89 | +stderr_logfile=/dev/stderr |
| 90 | +stderr_logfile_maxbytes=0 |
| 91 | +``` |
| 92 | + |
| 93 | +**Key differences:** |
| 94 | +- Alpine uses `depends_on` for process ordering |
| 95 | +- Debian uses `priority` (lower number starts first) |
| 96 | +- Debian requires a `[supervisord]` section with `nodaemon=true` |
| 97 | +- Debian needs `stdout_logfile_maxbytes=0` to disable log rotation for stdout/stderr |
| 98 | + |
| 99 | +### 2. Entrypoint Script |
| 100 | + |
| 101 | +**Alpine** uses `sh` shell with `su-exec`: |
| 102 | + |
| 103 | +```bash |
| 104 | +#!/bin/sh |
| 105 | +# ... |
| 106 | +exec su-exec kool "$@" |
| 107 | +``` |
| 108 | + |
| 109 | +**Debian** uses `bash` with `gosu`: |
| 110 | + |
| 111 | +```bash |
| 112 | +#!/bin/bash |
| 113 | +# ... |
| 114 | +exec gosu kool "$@" |
| 115 | +``` |
| 116 | + |
| 117 | +### 3. Package Installation |
| 118 | + |
| 119 | +**Alpine:** |
| 120 | +```dockerfile |
| 121 | +RUN apk add --no-cache nginx \ |
| 122 | + && apk add --no-cache --virtual .build-deps ... \ |
| 123 | + && apk del .build-deps |
| 124 | +``` |
| 125 | + |
| 126 | +**Debian:** |
| 127 | +```dockerfile |
| 128 | +RUN apt-get update \ |
| 129 | + && apt-get install -y --no-install-recommends nginx \ |
| 130 | + && rm -rf /var/lib/apt/lists/* |
| 131 | +``` |
| 132 | + |
| 133 | +### 4. nginx Directory Structure |
| 134 | + |
| 135 | +**Alpine:** |
| 136 | +```dockerfile |
| 137 | +chmod 770 /var/lib/nginx/tmp |
| 138 | +``` |
| 139 | + |
| 140 | +**Debian:** |
| 141 | +```dockerfile |
| 142 | +chmod 770 /var/lib/nginx |
| 143 | +``` |
| 144 | + |
| 145 | +## Migration Steps |
| 146 | + |
| 147 | +To migrate from Alpine to Debian: |
| 148 | + |
| 149 | +1. **Update your image tag:** |
| 150 | + ```yaml |
| 151 | + # docker-compose.yml |
| 152 | + # From: |
| 153 | + image: kooldev/php:8.4-nginx |
| 154 | + # To: |
| 155 | + image: kooldev/php:8.4-debian-nginx |
| 156 | + ``` |
| 157 | +
|
| 158 | +2. **Custom supervisor configs:** If you've customized the supervisor configuration, update to use `priority` instead of `depends_on` |
| 159 | + |
| 160 | +3. **Shell scripts:** Update any scripts that rely on Alpine-specific paths or BusyBox commands |
| 161 | + |
| 162 | +4. **Test thoroughly:** The glibc vs musl difference can cause subtle behavior changes in some applications |
| 163 | + |
| 164 | +## Available Debian Image Tags |
| 165 | + |
| 166 | +- `kooldev/php:8.4-debian` - Base FPM image |
| 167 | +- `kooldev/php:8.4-debian-prod` - Production FPM image (no dev tools) |
| 168 | +- `kooldev/php:8.4-debian-nginx` - FPM + Nginx with supervisord |
| 169 | +- `kooldev/php:8.4-debian-nginx-prod` - Production FPM + Nginx |
0 commit comments