Docker Community Forums

Share and learn in the Docker community.

Command line documentation (Where is the order of flags/arguments specified?)

Where do I find docker documentation that specifies the syntax for docker commands?

In particular, what is the order of a command-line command’s flags?

Here I try to execute a BusyBox container, naming the container jeremyNow, with the Docker run command.

Command Syntax I Tried Note
docker run -it --name jeremyNow busybox This command syntax successfully names
the container jeremyNow.
The --name flag precedes the image name.
docker run -it busybox --name jeremyNow This command syntax fails.
The --name flag follows the image name.
An error is returned.

Here is what I see in Terminal:

jeremyfrench@iMac docker empty folder % docker run -it --name jeremyNow busybox
/ # exit
jeremyfrench@iMac docker empty folder % docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS                     PORTS     NAMES
ab13b2c9ee2e   busybox   "sh"      8 seconds ago   Exited (0) 4 seconds ago             jeremyNow
jeremyfrench@iMac docker empty folder % docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
ab13b2c9ee2ebc1f0dec7595030f7005a15662542b22cd68244eb5ff404002fa

Total reclaimed space: 5B
jeremyfrench@iMac docker empty folder % docker run -it busybox --name jeremyNow
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "--name": executable file not found in $PATH: unknown.
ERRO[0000] error waiting for container: context canceled 
jeremyfrench@iMac docker empty folder % 

OS Version/build: macOS 11.6.2 (20G314)
App version: Docker version 20.10.11, build dea9396

This IS the general form that needs to be followed:

$ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG…]

The docker run [OPTIONS] are used to override the image defaults (“as in configure the container”).
Everything that follows IMAGE[:TAG|@DIGEST] are the command and it’s argument of the container.

Your first command uses --name jeremyNow as part of the container creation
your second command uses --name jeremyNow as runtime command and argument for inside the container. You tried to use a Docker OPTION as COMMAND and ARG to the buisybox container.