Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

What the Error Means

In docker run, docker pull, docker build -t, and docker tag, one word must be an image reference: an optional registry, a name, and an optional tag, such as registry.example.com/team/app:1.4. The rules are strict:

  • Name: lowercase letters, digits, and the separators ., _, and - between them, with / between parts. Only the registry host in front may add a port, as in registry.example.com:5000/app.
  • Tag: after one colon; up to 128 letters of either case, digits, _, ., and -, not starting with a dot or a dash.
  • Nothing else: no spaces, no https://, no second tag.

In docker run, the first word that is not an option or an option's value is taken as the image. Find that word and you have found the cause.

Uppercase Letters in the Name

Here the error usually adds that the repository name must be lowercase.

# broken
docker build -t MyApp .
# fixed
docker build -t myapp .

After the registry host, uppercase is allowed in the tag only, as in myapp:Release1, but lowercase everywhere is easier to remember.

A Path with a Space

When the current folder contains a space, an unquoted $(pwd) splits into two words, and the second half lands where the image should be:

# broken, in /home/deploy/my site
docker run -v $(pwd):/app node:26 node /app/server.js
# fixed
docker run -v "$(pwd)":/app node:26 node /app/server.js

The same applies to any -v path with a space: quote the whole value, as in -v "/srv/my data:/data".

An Empty Variable

# broken: TAG is not set, Docker sees "myapp:"
docker run -d myapp:$TAG
# fixed: stop with a message when it is empty
docker run -d "myapp:${TAG:?TAG is not set}"

In a Compose file, as used in docker compose up -d, image: myapp:${TAG} fails the same way. Compose replaces an unset variable with an empty string and understands the same ${TAG:?message} form. Check that the variable is set and exported in the shell that runs the command; see how to set environment variables in Linux.

Characters Copied from a Web Page

Blogs and word processors turn -d into a long dash and straight quotes into curly ones. Docker does not see an option then, only a word that is not valid ASCII, and takes it as the image:

# broken: the dash before d is a long dash
docker run –d -p 8080:80 nginx
# fixed: type the dash again
docker run -d -p 8080:80 nginx

An Option Split from Its Value

A stray space inside an option's value cuts it short, and the next piece becomes the image name. Here -p takes 8080 alone as its value:

# broken: ":" becomes the image name
docker run -d -p 8080 : 80 nginx
# fixed
docker run -d -p 8080:80 nginx

Options belong before the image. Anything after the image name is handed to the program inside the container, so docker run nginx -d does not fail with this error but runs a container that receives -d as its own argument.

A Backslash with a Trailing Space

A backslash continues a long command on the next line only if it is the last character. With an invisible space after it, the shell passes a lone space as a word, which Docker reads as the image name, and ends the command at the line break. The next line then runs as a command of its own. The script looks correct on screen, so search for the pattern instead:

grep -n '\\ $' deploy.sh
sed -i 's/[[:space:]]*$//' deploy.sh

The first command lists every line that ends in a backslash and a space. The second removes trailing whitespace from all lines; keep a copy of the script before editing it in place.

Bad Tags and Registry Addresses

# broken
docker pull https://registry.example.com/app:1.4
docker pull app:1.4:latest
# fixed
docker pull registry.example.com/app:1.4

A registry is written without a scheme, and an image has one tag per reference.

How to Find the Culprit

Print the command with every variable expanded before running it:

set -x
docker run -d -v "$(pwd)":/app myapp:$TAG
set +x

The shell shows each word as Docker receives it. Look at the first word after the options: that is the reference Docker rejected. For variables in scripts, see the quoting rules in the bash if statement guide.

Was this answer helpful?
Loading...