drago-ex / project-docker
Basic configuration of a php server on docker.
Package info
github.com/drago-ex/project-docker
Language:Dockerfile
Type:drago-tools-resource
pkg:composer/drago-ex/project-docker
Requires
- php: >=8.3 <9
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The Docker setup of Drago Project: a PHP 8 Apache server with the project in the image, live sync of changes for development and secure defaults for production.
Requirements
- PHP >= 8.3, < 9
- Drago Project
- Docker
Installation
composer require drago-ex/project-docker
Project Tools copies docker/, docker-compose.yaml and
.dockerignore into the project, where you adapt them. Drago Project installs the package by itself.
Project in the Image
The project is copied into the image (docker/Dockerfile-app) instead of being mounted from your disk, which is
slow on Windows. Run docker compose watch (or npm run docker:dev) while you work: it copies every change of
app/ and www/ into the running container and builds a new image when composer.lock changes. Only log/
and www/upload/ are mounted, so logs are visible and uploaded files outlast a new image; what .dockerignore
lists is not copied.
After changing vendor/ without composer.lock, build the image again with docker compose up -d --build.
PHP Extensions
The image has GD (JPEG, PNG, WebP) for resizing uploaded images and intl for slugs made from names;
docker/php.ini sets the upload limits (64 MB) and memory_limit (256 MB, enough to resize photos).
Security
- Debug mode (Tracy) is off unless asked for:
npm run docker:devloadsdocker/.env.development(NETTE_DEBUG=1, andPHP_EXCEPTION_IGNORE_ARGS=0keeps function arguments in stack traces), a plaindocker compose upandnpm run docker:productionrun without it. - The server listens only on
127.0.0.1:8080. To publish it on every interface, setSERVER_PORT=8080; Docker bypasses firewalls such asufw, so in production prefer an HTTPS reverse proxy in front of it. - PHP never runs in
www/upload/, and an uploaded.htaccessis ignored. Files from there are served with aContent-Security-Policythat runs no script, so an uploaded SVG or HTML file opened directly cannot attack the site. docker/php.inihides the PHP version, logs errors instead of showing them, leaves function arguments out of stack traces outside development (also whenPHP_EXCEPTION_IGNORE_ARGSis not set), limitsmax_execution_timeto 60 s and makes session cookies strict, HttpOnly and SameSite.disable_functionsis ready to uncomment when nothing in the container runs shell commands (the PHP CLI, e.g. Composer, reads the same file).- Behind a reverse proxy, tell Nette to trust it in
app.neon, so it sees the visitor's IP address and HTTPS:http: proxy: 172.16.0.0/12 # the address or range of your proxy
Without it every request comes from the proxy's address, so the sign-in limit of project-auth would block all visitors at once, and Nette would not mark the session cookie secure (it does so by itself on HTTPS). - Apache hides its version (
docker/conf/security.conf) and sendsX-Content-Type-OptionsandReferrer-Policy. - Rebuild the image regularly with
docker compose build --pullto get security fixes of PHP and Debian.
Docker Commands
Drago Project has the npm scripts of package.json:
| Script | Does |
|---|---|
npm run docker:build |
builds the images from scratch |
npm run docker:dev |
starts the containers in debug mode and syncs changes into them |
npm run docker:production |
starts the containers without debug mode |
npm run docker:down |
stops and removes the containers (the data volumes stay) |