knowads
knowads

Reputation: 795

Is there a way to automatically "Rebase" an image in Docker?

I have a docker-compose script that brings up a service

version : '2.0'
services:
        orig-db:
             image: web-url:{image_tag}
        custom-db:
             image: local_image: latest

Where image used in custom DB is the the result of bringing up a container with orig-db, performing some basic bash commands, and doing a docker commit. I want the custom-db image to always be the original image + these commands, even if the original image is updated. Is there a way to "rebase" off the original image?

Upvotes: 0

Views: 1809

Answers (1)

sauerburger
sauerburger

Reputation: 5138

You can think of a Dockerfile as a simple form of a "rebase".

# Content of subdir/Dockerfile
FROM orig_image:latest

RUN some.sh
RUN basic.sh
RUN bash_commands.sh

When you build an image based on this file, it will always run the bash commands on top of the base image. Inside the compose file you can use the build property to instruct docker-compose to build the image instead of using a pre-made image.

version : '2.0'
services:
    orig-db:
         image: web-url:{image_tag}
    custom-db:
         build: somedir

If the base image changes, you need to tell docker-compose to rebuild the custom-db image again, running the bash commands again on top of the updated original image.

docker-compose up -d --build custom-db

Upvotes: 1

Related Questions