Is it possible to run docker-compose up
in such a way that it will only build if the image isn't present in the repository?
I'm working on a test scenario that will run in two different environments: locally on a laptop, and on a server as part of test automation. My docker-compose file looks something like this:
services:
my-service1:
build: "./local-repo1"
image: "image1"
my-service2:
build: "./local-repo2"
image: "image2"
...
If I run it locally where the local-repo directories exist it runs fine. If I try to run it on the server where it instead pulls from a docker repository it complains that it cannot find the build path. If I take out the build
property it runs fine on the server, but then it won't run locally unless I build the images beforehand.
Is there a way to make it only try to build if the image doesn't already exist? If not I can try some workarounds, but I'd prefer to use just one docker-compose file that handles each case.