When defining a multi service environment with Docker and Docker Compose, the usual way was to use a Dockerfile for each service, starting with the base image and adding all custom needs:
/env/php/Dockerfile
FROM php:7.2-fpm-alpine3.7 RUN docker-php-ext-install opcache
/env/nginx/Dockerfile
FROM nginx:1.15-alpine ADD virtual-host.conf /etc/nginx/conf.d/default.conf
Then you could compose all services.
/docker-compose.yml
version: '3' services: php: build: context: ./env/php volumes: - ./:/app working_dir: /app restart: unless-stopped nginx: build: context: ./env/nginx volumes: - ./:/app ports: - "80:80" restart: unless-stopped
ThenĀ Docker 17.05 introduced multi-stage builds, allowing to use one Dockerfile. Continue reading Docker multi-stage builds with Docker Compose