I have a few images that share common code but are not exactly the same.
Is there a way to create a base image in docker-compose so that it will not run itself when doing docker-compose up
and I will be able to extend it in my Dockerfiles?
Here is example what I want to achieve:
version: '3'
services:
php:
build:
context: .
dockerfile: ./php/Dockerfile
php-fpm:
build:
context: .
dockerfile: ./php-fpm/Dockerfile
php-cron:
build:
context: .
dockerfile: ./php-cron/Dockerfile
php-worker:
build:
context: .
dockerfile: ./php-worker/Dockerfile
Base dockerfile
FROM php:7.2-fpm-alpine
RUN docker-php-ext-install bcmath
... and other extensions
And the other dockerfiles (with small variations):
php-fpm
FROM my-docker-compose:php
RUN docker-php-ext-install php-fpm
CMD php-fpm
php-cron
FROM my-docker-compose:php
COPY php/crontab /tmp/crontab
RUN /usr/bin/crontab -u www-data /tmp/crontab
CMD crond