How can I run a script between two services specified in a docker-compose file?

Suppose I have two services, where b needs to be created before a. I can use a docker-compose file like this:

services: a: image: a depends_on: - b b: image: b 

But I need to run a script foobar.sh in the “host” e.g. the same directory, network, etc. as the docker-compose.yml file. How can I accomplish this? Would I create another service called foobar and add another entry in depends_on? Are they performed in order? Bascially anytime b is rebuilt, I need the script run before a is built.

submitted by /u/IvankasPantyLiner
[link] [comments]
Source: Reddit