docker-compose.yml override remove build for image

Viewed 963

I have:

docker-compose.yml:

services:
  app:
    build: .

and docker-compose.override.yml:

services:
  app:
    image: my_repo/my_app:my_tag

When I do docker-compose up, it actually does build: . instead of using the overriden image: my_repo/my_app:my_tag.

I guess I should go for some kind of build: false or build: none to make sure it reads the image attribute, shouldn't I? Since override seems to act like a merge, it would result as if both entries were there:

services:
  app:
    build: .
    image: my_repo/my_app:my_tag

and it seems like build is prioritary to image (from the docs).

1 Answers

I believe the correct way to do it is to have a base docker-compose.yml like :

services:
  app:
    image: my_repo/my_app:my_tag

and the docker-compose.override.yml :

services:
  app:
    build: .

This way when you launch docker-compose up the image will be built with build context .

Another example with docker-compose.override.yml with different image :

services:
  app:
    image : my_repo/other_image:tag

And here the image from docker-compose.override.yml will take precedence.

Related