Skip to content

Build same images only once, even they are used in multiple services #7343

Description

@adaamz

Is your feature request related to a problem? Please describe.
I'm always frustrated when same image is built multiple times.

Describe the solution you'd like
If one image (with same tag) is used in multiple services, docker-compose should be smart enough to not build it multiple times.

Describe alternatives you've considered
No existing alternative, docker-compose up --build also build it multiple times. Also I'm unable to use proper caching, because of #7342 problem.

Additional context
This docker-compose.yml should build only one image web:${TAG} once, not twice, when running command docker-compose build/docker-compose up --build.
Also when I run docker-compose up my-web/my-web-saver, it should build the image if not exists.

version: '3.2'
services:
    my-web:
        image: web:${TAG}
        build:
            cache_from:
                - web:${TAG}
                - web:latest
            context: web
            dockerfile: web/Dockerfile

    my-web-saver:
        image: web:${TAG}
        build:
            cache_from:
                - web:${TAG}
                - web:latest
            context: web
            dockerfile: web/Dockerfile

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions