Reputation: 2101
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
Upvotes: 8
Views: 1981
Reputation: 15569
You would typically accomplish this by storing your base images in a Docker registry. You can either store them in the public registry (https://hub.docker.com) or some private registry (either hosted in the cloud our on premise).
Here is more information on Docker registry: https://docs.docker.com/registry/
Some additional information on using base images: https://docs.docker.com/develop/develop-images/baseimages/
Upvotes: 1