What does it mean that `docker run --network = container: CONTAINERID`?
I know that when starting the container, I can set an argument --network
whose value can be any of the results docker network ls
.
However, I've seen some launch containers look like this:
$ docker run --network=container:CONTAINERID IMAGE
I searched for this usage but didn't get any docs to explain it.
I did some experimentation and found that a container using a different container network has the same networking stack and it seems that the two containers are on the same host
and they can call each other using localhost
.
So, when starting a container, setting --network=container:CONTAINERID
, does that mean the two containers have the same networking stack?
source to share
Exactly as you thought, the new container is assigned the same network namespace as CONTAINERID
. So yes, the same networking stack. As you have defined, this means that containers can communicate with each other through localhost, which also means that you need to be careful with port mappings as each container will need a unique port in the namespace.
This is described in the docker run
link here .
--network="bridge" : Connect a container to a network
'bridge': create a network stack on the default
Docker bridge
'none': no networking
# -----> 'container:<name|id>': reuse another container
network stack
'host': use the Docker host network stack
'<network-name>|<network-id>': connect to a
user-defined network
source to share