Skip to content
Latchkey

Docker "invalid reference format" - Fix Bad Image Names in CI

Docker rejected the image reference before contacting any registry because it does not match the grammar for a valid name and tag.

What this error means

A docker build -t, docker tag, docker pull, or docker run fails instantly with invalid reference format, sometimes adding repository name must be lowercase. No network call is made.

Terminal
docker: invalid reference format: repository name must be lowercase.
# e.g. from: docker build -t MyOrg/API:Latest .  or an empty ${IMAGE} variable

Common causes

Uppercase letters or illegal characters

Repository names must be lowercase and may only contain a restricted character set. MyOrg/API, spaces, or stray characters break the grammar.

An unsubstituted or empty variable

A reference like ${REGISTRY}/api:${TAG} where a variable is empty collapses to something malformed (/api: or :latest with a leading colon), which Docker cannot parse.

Malformed digest or double separators

A bad @sha256: digest, a double slash, or a trailing colon produces a reference that fails validation.

How to fix it

Lowercase the name and remove illegal characters

Normalize the repository name; lowercase any branch or org value interpolated into it.

Terminal
IMAGE="ghcr.io/${OWNER,,}/api:${TAG}"   # bash lowercases OWNER
docker build -t "$IMAGE" .

Echo the reference before using it

Print the fully-expanded reference so an empty variable is obvious.

Terminal
echo "building: ${REGISTRY}/api:${TAG}"
test -n "${TAG}" || { echo "TAG is empty"; exit 1; }

How to prevent it

  • Lowercase any dynamic org/branch values before putting them in an image name.
  • Default tag variables and assert they are non-empty before building.
  • Keep image references in one place so the grammar is easy to audit.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →