Does the order of the options matter?

Hi everyone, I’m new to Docker and trying to understand how the --name option works when running a container.

I ran the following two commands:

docker run -d --name simple-user-api -p 8080:8080 -t simple-user-api:7th
docker run -d -p 8080:8080 -t simple-user-api:7th --name simple-user-api

In the first command, the container gets the name simple-user-api as expected. However, in the second command, the container runs without a name, and Docker assigns a random one instead.

I thought --name would work the same way in both cases, but it seems like the order of the options affects the result.

Could someone please explain why this happens? Does the order of options in docker run matter? If there’s a specific part of the Docker documentation that covers this, I would love to check it out.

Thanks in advance! :blush:

All Docker options need to come before the image name (doc). Everything after the image name is passed to the container.

docker container run [OPTIONS] IMAGE [COMMAND] [ARG...]
1 Like

Thank you for your reply :blush:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.