docker-php
Skill4 starsChanged 4 months agoMITView on GitHub
Build lean, production-ready PHP-FPM container images — multi-stage builds, minimal base images, Composer dependency caching, and opcache tuning for prod. Use when the user wants to package a PHP-FPM application into a Docker image for deployment; the user wants to configure PHP opcache (and JIT) inside a production container image; the user wants to shrink a bloated PHP Docker image or speed up its build. Keywords: docker, php-fpm, multi-stage, image-size, opcache, containers.
- Reads credentials
- Deletes or force-pushes
In this repository119 other files it gives its agents.
- strategy-bitrix-d7-incrementalSkill
- strategy-explicit-over-magicSkill
- strategy-framework-conventionsSkill
- strategy-legacy-safe-editsSkill
- strategy-minimal-diffSkill
- strategy-no-untested-refactorSkill
- strategy-preserve-public-apiSkill
- strategy-readonly-immutabilitySkill
- strategy-security-firstSkill
- strategy-test-drivenSkill
- openapiSkill
- paginationSkill
- rest-designSkill
- versioningSkill
- cqrsSkill
- dependency-inversionSkill
- hexagonalSkill
- repository-patternSkill
- service-layerSkill
- bitrixSkill
- findings-reportSkill
- laravelSkill
- performanceSkill
- phpSkill
- project-analysisSkill
- refactoringSkill
- roi-prioritizationSkill
- securitySkill
- stack-detectionSkill
- cache-layersSkill
- component-engineSkill
- d7-eventsSkill
- d7-loaderSkill
- d7-orm-queriesSkill
- iblock-elementsSkill
- kernel-main-moduleSkill
- localizationSkill
- controllersSkill
- ormSkill
- validationSkill
- controllersSkill
- query-builderSkill
- routingSkill
- autoload-psr4Skill
- dependency-managementSkill
- scriptsSkill
- connection-poolingSkill
- mysql-indexingSkill
- redisSkill
- transactionsSkill
- ci-github-actionsSkill
- deployment-strategiesSkill
- env-configSkill
- associationsSkill
- entities-mappingSkill
- orm-basicsSkill
- entity-apiSkill
- module-developmentSkill
- routing-controllersSkill
- formsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 64
Do not apply production image hardening when the user only wants a throwaway local dev container with bind-mounted source.
- Distinctive: line 65
Do not use this skill for Kubernetes manifests, service meshes, or multi-service orchestration concerns.
- Very specific: line 78
Start a composer build stage, copy composer.json/composer.lock, and run composer install --no-dev --optimize-autoloader before copying …
- Very specific: line 91
Create an unprivileged user in the image and set USER so the FPM master and workers do not run as root
- Distinctive: line 120
Not applicable — no I/O, auth, or untrusted input.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!-- generated: do not edit — source: knowledge/atoms/devops/docker-php/ --><!-- schema: atomVersion=3 skillVersion=2 graphVersion=1 --><!-- compile: @php-skills/compiler v1.0.0 (deterministic build) -->Dockerizing PHP-FPM
When to use
- The user wants to package a PHP-FPM application into a Docker image for deployment.
- The user wants to configure PHP opcache (and JIT) inside a production container image.
- The user wants to shrink a bloated PHP Docker image or speed up its build.
When NOT to use
- Do not apply production image hardening when the user only wants a throwaway local dev container with bind-mounted source.
- Do not use this skill for Kubernetes manifests, service meshes, or multi-service orchestration concerns.
Core guidance
- Prefer official php-fpm-alpine, pin the exact tag — Base the runtime on an official
php:<version>-fpm-alpineimage and pin the full version tag (e.g.php:8.3.14-fpm-alpine) rather thanlatestor a bare major. - Use a multi-stage build to keep the runtime image lean — Split the Dockerfile into a build stage (Composer, node, compilers) and a
slim runtime stage that copies only
vendor/and the application code. - Enable opcache with validate_timestamps=0 in production images — In production images set
opcache.enable=1,opcache.validate_timestamps=0, and a generousopcache.memory_consumption; never disable timestamp validation locally.
Quick recipe
- Start a
composerbuild stage, copycomposer.json/composer.lock, and runcomposer install --no-dev --optimize-autoloaderbefore copying source. (verify: The build stage produces a populatedvendor/directory) - In a
php:<version>-fpm-alpineruntime stage, install required extensions, thenCOPY --from=buildthe application andvendor/, and set a non-rootUSER. (verify:docker run --rm img php -mlists every extension the app needs) - Copy a
docker-php-ext-opcacheini enabling opcache withvalidate_timestamps=0intoconf.d, then verify throughput. (verify:php -i | grep opcache.enableshowsOnand timestamps validation off)
Best practices
- Run
composer install --no-dev --optimize-autoloader --no-interaction --prefer-distin the build stage so dev tooling and unoptimized autoloading never ship - Copy
composer.jsonandcomposer.lock, runcomposer install, and only thenCOPYthe application source, so the vendored dependency layer is cached - Create an unprivileged user in the image and set
USERso the FPM master and workers do not run as root
Anti-patterns
| Anti-pattern | Why it fails | Do instead |
| Baking .env and secrets into the image | Anyone who pulls the image (or reads a layer) can extract the secrets; image layers are not encrypted. | Inject configuration at runtime via environment variables or a secrets manager, and add .env to .dockerignore. |
| Single-stage image carrying Composer and compilers | Build tooling doubles or triples image size and adds a large exploitable surface in production. | Move all build tooling into a discarded build stage and copy only vendor plus source into a slim runtime stage. |
| Building FROM php:latest | The resolved PHP version drifts between builds, so a rebuild can silently jump versions and break the app. | Pin the full patch version and variant, e.g. FROM php:8.3.14-fpm-alpine, and bump it deliberately. |
See references/anti-patterns.md.
Common mistakes
- Package manager cache bloats the image — Leaving
apt/apkcaches and build-only-devpackages in the final layer inflates the image by hundreds of MB. Fix: Useapk add --no-cache, or for apt runrm -rf /var/lib/apt/lists/*in the sameRUN, and remove build-only packages after compiling extensions. - Assuming PHP extensions ship with the base image — The official PHP images ship a minimal extension set;
pdo_mysql,intl,gd, andzipare not present by default. Fix: Install extensions explicitly withdocker-php-ext-install(orpecl installplusdocker-php-ext-enable) in the build stage and verify withphp -m. - validate_timestamps=0 serves stale code after a deploy — With
opcache.validate_timestamps=0, editing files in a running container has no effect — PHP keeps serving the cached bytecode. Fix: Treat the image as immutable — build a new image per release and restart the container; never hot-edit files in avalidate_timestamps=0production container.
Version notes
- Opcache JIT available from PHP 8.0 (PHP >=8.0) — The opcache JIT (
opcache.jit,opcache.jit_buffer_size) is available from PHP 8.0; on 7.4 images tune classic opcache only.
Security
- Not applicable — no I/O, auth, or untrusted input.
Testing
- Activation and decision behavior are verified in
eval/scenarios/devops/docker-php.yaml.
Additional resources
- references/anti-patterns.md
- references/core.md
- references/examples.md
- references/pitfalls.md
- references/recipes.md
- references/version-differences.md
Knowledge graph
Related: databases/redis, devops/ci-github-actions, devops/deployment-strategies, devops/env-config
<!-- graph-fragment: graph/fragments/devops/docker-php.yaml -->Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

