You can customize and extend the Docker Compose configuration without modifying the core files. This allows you to receive updates while maintaining your custom configuration.
The docker-custom.yml file is gitignored and allows you to override or extend any service configuration.
Create the file in your development root:
cd ~/development
nano docker-custom.ymlversion: '2'
services:
servicename:
# Your customizations hereTo add custom components to the PHP container:
1. Create docker-custom.yml:
version: '2'
services:
php:
build: custom/php2. Create custom Dockerfile:
mkdir -p custom/php
nano custom/php/Dockerfile3. Extend the base PHP image:
FROM ghcr.io/jeroenboersma/php-development:8.2-fpm
# Install additional packages
RUN apt-get update && apt-get install -y \
your-package-here \
&& rm -rf /var/lib/apt/lists/*
# Install additional PHP extensions
RUN docker-php-ext-install extensionname
# Copy custom configuration
COPY custom-config.ini /usr/local/etc/php/conf.d/4. Rebuild:
dev rebuildversion: '2'
services:
db:
environment:
MYSQL_ROOT_PASSWORD: mycustompassword
php82:
environment:
PHP_MEMORY_LIMIT: 512Mversion: '2'
services:
php:
volumes:
- /path/on/host:/path/in/containerversion: '2'
services:
web:
ports:
- "8080:80"For project-specific overrides, use docker-compose-dev.yml. This can be committed to your project repository.
Place it in your project directory:
cd workspace/customer/project
nano docker-compose-dev.ymlThe ./custom directory is gitignored and meant for your customizations:
custom/
├── php/
│ ├── Dockerfile
│ └── config.ini
├── nginx/
│ └── custom-site.conf
└── mysql/
└── custom.cnf
Docker Compose automatically merges configurations in this order:
docker-compose.yml(base)build/dist/docker-compose-*.yml(enabled services)docker-custom.yml(your customizations)docker-compose-dev.yml(project-specific)
Later files override earlier ones.
- Use
docker-custom.ymlfor personal/environment-specific changes - Use
docker-compose-dev.ymlfor project-specific changes - Document your customizations
- Keep custom Dockerfiles simple
- Modify core
docker-compose.ymldirectly (you'll lose changes on update) - Commit
docker-custom.ymlto version control - Override critical service dependencies
- Make breaking changes to service names/networks
version: '2'
services:
myservice:
image: myimage:latest
networks:
- default
volumes:
- dockerdev-workspace-volume:/dataversion: '2'
services:
php:
build:
context: build/dist/php
args:
PHP_VERSION: 8.3version: '2'
services:
myservice:
networks:
mynetwork:
ipv4_address: 172.25.0.100
networks:
mynetwork:
driver: bridge
ipam:
config:
- subnet: 172.25.0.0/16Always rebuild after modifying compose files:
dev rebuildCheck the merged configuration:
dev configThis shows the final composed configuration.
Validate your YAML:
docker-compose -f docker-custom.yml configEnsure you're using the correct file name:
docker-custom.yml(notdocker-custom.yaml)- Place it in the development root directory
Force recreation:
dev down
dev up --force-recreate- customize-docker-containers.md - Basic customization guide
- environment-configuration.md - Environment variables