0

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?

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

What does "somedir" represent in the build property? Is that the subdirectory of the docker file?
Sorry for not being clear enough. somedir is a new directory in which the Dockerfile is located. The name is arbitrary. I principle, you don't need to put the Dockerfile in a subdirectory, but in case you want to add more files, it's cleaner if you use a separate directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.