Skip to main content

CV-B008: Both build and image specified

Warning Best Practice

Why This Matters

When a service specifies both "build" and "image", Docker Compose builds the image from the Dockerfile and tags it with the "image" name. While this is valid, it can cause confusion. Developers may expect "image" to pull a pre-built image, not realize a local build occurs, or accidentally push locally-built images to a registry.

How to Fix

Use either build (for local builds) or image (for pre-built images), not both, unless intentionally tagging build output

Before (incorrect)

services:
  web:
    build: .
    image: myapp:latest

After (correct)

services:
  web:
    build: .

Rule Details

Rule Code
CV-B008
Severity
Warning
Category
Best Practice

Related Rules