Seven services with the same logging configuration, the same restart policy and the same network means the same six lines seven times, and the one that gets missed is the one that matters.
version: '3.7'
x-defaults: &defaults
restart: unless-stopped
networks: [app]
logging:
driver: json-file
options: { max-size: '10m', max-file: '3' }
services:
php:
<<: *defaults
build: ./docker/php
nginx:
<<: *defaults
build: ./docker/nginx
Any top-level key beginning x- is ignored by compose and available as a YAML anchor, which is how this works — it is not a compose feature so much as compose agreeing not to interfere with one. The log rotation options are the ones worth applying everywhere: the default json-file driver has no limit, and a chatty container will quietly consume the host disk over a fortnight.