Difference between 'image' and 'build' within docker compose

meallhour picture meallhour · Dec 16, 2015 · Viewed 12.3k times · Source

Please help me understand the difference between 'image' and 'build' within docker compose

Answer

VonC picture VonC · Dec 16, 2015
  • image means docker compose will run a container based on that image
  • build means docker compose will first build an image based on the Dockerfile found in the path associated with build (and then run a container based on that image).

PR 2458 was eventually merged to allow both (and use image as the image name when building, if it exists).

therobyouknow mentions in the comments:

dockerfile: as a sub-statement beneath build: can be used to specify the filename/path of the Dockerfile.

version: '3'
services:
  webapp:
    build:
      context: ./dir
      dockerfile: Dockerfile-alternate
      args:
        buildno: 1