How should I write the --network option of docker run command

Hi, all.
I happend to see that the --network option of docker run command seems to take two forms: “–network ” and “–network=” (one seperated by blank and the other by equal sign). Is it correct? Is it better to use equal sign?

thanks, matsuand

It doesn’t matter. Both are correct. The network option is not the only option that can be used both ways and many command line applications support both. Some people may find it better for their eyes to use it as one argument:

--network=mynet

So they can recognize easier when they use a “flag” which does not require a value. If you forget to use the value it can be hard to notice and the next agument becomes the value of it.

docker run -d --network bash whoami

This command would try to use an image called “whoami” instead of “bash” because “bash” will be the argument of the --network option. If you write it this way:

docker run -d --network=bash whoami

you can immediately notice that bash can’t be the value of the option and the image name is missing.
Despite all of these I usually prefer the first syntax. I can’t explain it, but with my experience I can recognize a missing value easier based on the error message so that is not a problem for me. So just to share a correct command to avoid confusing future readers, this is how I use the command:

docker run -d --network mynetwork bash whoami

It is not a recommendation, it is only my personal preference.

Very much thanks for your polite answer. I got it ^^