Is there a way to have both build:
and image:
specified in a docker-compose yaml file and have them play nice?
Ideally, the remote image is pulled on docker-compose up
, and are built instead when docker-compose up --build
or docker-compose build
are run. The issue is a bit of a nuisance when developers must comment out the build param to pull the remote image.
build: ./nginx
image: us.gcr.io/cool-project-123456/dev-box:latest
Build is always run, and then names and tags the container with the image:
value.
# build: ./nginx
image: us.gcr.io/cool-project-123456/dev-box:latest
Here it seems that as long as build:
is commented, and image:
exists, all build commands are ignored and the image is pulled instead.
Example 1 is not always run. It runs only when your don't have that image: us.gcr.io/cool-project-123456/dev-box:latest
docker-compose up
is always using existing images in your machine first.
My suggestion is keeping
build: ./nginx
image: us.gcr.io/cool-project-123456/dev-box:latest
and using
docker-compose up --build
docker-compose pull & docker-compose up