docker: 'docker run' requires at least 1 argument means the command reached
Docker with no image name in it. In the case reproduced here, the image came from a shell
variable that was empty, so the line ended after the options. Put an image name after the
options, or make sure the variable is set before the command runs.
docker run expects options first, then the image, then an optional command:
the usage line it prints says exactly that. Two cases were captured: a bare
docker run, and options followed by an empty variable where the image belonged.
The error
> docker run --rm -p 127.0.0.1:15934:8080 %IMAGE% (IMAGE is empty)
docker: 'docker run' requires at least 1 argument
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
See 'docker run --help' for more information
exit=1
Why it happens
The shell expands the variable before Docker sees anything. With IMAGE empty,
the command Docker received was docker run --rm -p 127.0.0.1:15934:8080:
the --rm flag, the -p option with its value, and no image. Running a bare docker run prints
the same three lines, which is the quickest way to recognise the message.
The message does not mention the variable, because Docker never saw it; all it got was a line with nothing in the image slot. When a script builds the command from variables, print the command before you run it, or guard the variable as shown below.
The fix
> docker run --rm -d --name fix10-dc-r7 -p 127.0.0.1:15934:8080 %IMAGE% (IMAGE=fix10-dc-web:good)
6c24c9818e643f08258fa6d5cd5fb067776b57c7996f353aaff4704aa2224f9e
exit=0
With the variable set to an image name, the container started, and
curl.exe -sS http://127.0.0.1:15934/ answered Hello World!. In a
script, fail early when the variable is empty instead of letting Docker report it. In cmd,
if not defined IMAGE exit /b 1 returned exit code 1 with IMAGE empty. In bash,
${IMAGE:?IMAGE is not set} stopped before the line ran:
> docker run --rm --name fix10-dc-r7b ubuntu:24.04 bash -c "IMAGE=; docker_line() { echo docker run --rm ${IMAGE:?IMAGE is not set}; }; docker_line; echo reached"
environment: line 1: IMAGE: IMAGE is not set
exit=127
The word reached never printed: the script ended at the guard with a message
that names the variable.
How it was reproduced
Docker client and engine 29.9.3 on Windows, commands run from a cmd batch file with stderr
merged into stdout, each one echoed with > and followed by its exit code. The
image in the fix is the test's own, an ASP.NET Core dotnet new web app on
mcr.microsoft.com/dotnet/aspnet:10.0, published on 127.0.0.1 only. A bare
docker run with no arguments printed the same message. The container and image
names are the test's own.
Frequently asked
- What does docker run requires at least 1 argument mean?
- Docker received a run command with no image name. In the test the image came from an empty variable, so only the options reached Docker. Put the image name after the options.
- What order do docker run arguments go in?
- Options first, then the image, then an optional command and its arguments. The usage line Docker prints with this error is docker run [OPTIONS] IMAGE [COMMAND] [ARG...].
- How do I stop a script when the Docker image variable is empty?
- Check the variable before the docker line. In cmd use if not defined IMAGE exit /b 1; in bash use ${IMAGE:?IMAGE is not set}, which stops with a message naming the variable.
More decoded errors in the Fixes category.