28

Is there a way before building of docker containers with docker compose to execute a bash script?

something like

version: "3"
before_script: //execute my local script 
services:
  database: ....

1 Answer 1

23

No there is not.

you can make a custom bash build script that executes your local script before starting the containers

Sign up to request clarification or add additional context in comments.

3 Comments

why is there no such an option????
Because the docker-compose devs say it will "break compatibility" because, for instance, Windows doesn't have bash by default. github.com/docker/compose/issues/6736
I don't see how the compatibility argument makes sense. Docker compose can use Dockerfiles or inline Dockerfile syntax and those have a SHELL= command. So there is nothing to stop there being a stage that is platform dependent if that particular project is cross platform. It would be more useful to have it than to omit it on made up grounds. e.g. I want to unmount a bind mount during build to prevent files from being copied to the image. The --exclude seems very broken and unreliable.

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.