How to prevent docker-compose building the same image multiple times?

Per the docker-compose file documentation for build, specify build: and image: for the first service, and then only image: for subsequent services.

Here’s a modified version of your example that only builds the image once (for abc service) and reuses that image for xyz service.

version: '2'
services:

  abc:
    image: myimage
    command: abc
    build:
      context: .
      dockerfile: Dockerfile

  xyz:
    image: myimage
    command: xyz

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)