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!