Attaching a docker container to another container's network with --net=container:containerName keyWhy would anyone use the same network namespace for two docker containers?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersExploring Docker container's file systemCopying files from Docker container to hostCopying files from host to Docker containerHow to copy Docker images from one host to another without using a repositoryFrom inside of a Docker container, how do I connect to the localhost of the machine?How do I get into a Docker container's shell?Docker bridge network, HTTP calls between containers VERY slow (after docker upgrade)
How to count the number of function evaluations in NIntegrate
Simulate a 1D Game-of-Life-ish Model
Is there an in-universe reason Harry says this or is this simply a Rowling mistake?
What is the expected way to acquire costly material components?
Do you add your strength modifier once or twice to an unarmed strike?
Twelve Minesweeper mines that make twelve 4s
I was cheated into a job and want to leave ASAP, what do I tell my interviewers?
Manager manipulates my leaves, what's in it for him?
4h 40m delay caused by aircraft inspection, Norwegian refuses EU 261/2004 compensation because it turned out there was nothing wrong with the aircraft
How to influence manager to not schedule team meetings during lunch?
Make Interviewee Comfortable in Potentially Intimate Environment
Madrid to London w/ Expired 90/180 days stay as US citizen
Borrowing observations for prior probability in Bayesian Inference
Get the encrypted payload from an unencrypted wrapper PDF document
rule-based deletions from string list
Does battery condition have anything to do with macbook pro performance?
Exam design: give maximum score per question or not?
Algorithm for competing cells of 0s and 1s
How could artificial intelligence harm us?
Did HaShem ever command a Navi (Prophet) to break a law?
Delete empty subfolders, keep parent folder
Removing rows containing NA in every column
Availability Group Notification when new DB is added
Should the pagination be reset when changing the order?
Attaching a docker container to another container's network with --net=container:containerName key
Why would anyone use the same network namespace for two docker containers?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersExploring Docker container's file systemCopying files from Docker container to hostCopying files from host to Docker containerHow to copy Docker images from one host to another without using a repositoryFrom inside of a Docker container, how do I connect to the localhost of the machine?How do I get into a Docker container's shell?Docker bridge network, HTTP calls between containers VERY slow (after docker upgrade)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm reading the book "Docker and Kubernetes for Java Developers" by Jaroslaw Krochmalski, and I've stumbled upon the following example. The author proposes to create a bridged myNetwork
network and then run two containers (Apache Tomcat and BusyBox) attached to this network, as follows (the commands should be run in separate terminal sessions):
$ docker run -it --name myTomcat --net=myNetwork tomcat
$ docker run -it --net container:myTomcat busybox
The author specificaly says that "we want our busybox container to use the same network as Tomcat uses. As an alternative, we could of course go with specifying a network name explicitly, using the --net myNetwork
option".
Then the author proposes to check the communication between the containers by running the following command in the busybox container:
$ wget localhost:8080
This indeed worked, but immediately confused me, since we have two different containers, and it's not clear why do they communicate via localhost. Turns out, the above mentioned command with a --net container:myTomcat
key doesn't exactly add the container to the network, but makes it somehow visible under the same IP as the myTomcat
container.
This is confirmed by the observation that if you run docker network inspect myNetwork
, you will see that there's actually only one container attached to the network:
[
"Name": "myNetwork",
...
"Containers":
"464ed70a0c31784226dc943bcbcb79f7c4666b9d7825183706505731ac06a9bf":
"Name": "myTomcat",
"EndpointID": "a4c384f17c6f8e443a430f130093ff6936bb59b1b54d0f056d1f0b4c703c1489",
"MacAddress": "02:42:ac:14:00:02",
"IPv4Address": "172.20.0.2/16",
"IPv6Address": ""
,
...
]
On the contrary, if you run the busybox
container as follows:
$ docker run -it --net=myNetwork busybox
the visibility through localhost
won't work, but the docker network inspect myNetwork
will show both containers attached to the network under different IPs:
[
"Name": "myNetwork",
...
"Containers":
"41c607b78af36cf6512124b6c057ed31997ddd6067a99ae579fe25b53753178e":
"Name": "vigorous_clarke",
"EndpointID": "9bf6d6a294d885febcfe7f38e388f68af3f8bc7c0334c1dcea13512c3ead23d5",
"MacAddress": "02:42:ac:14:00:03",
"IPv4Address": "172.20.0.3/16",
"IPv6Address": ""
,
"464ed70a0c31784226dc943bcbcb79f7c4666b9d7825183706505731ac06a9bf":
"Name": "myTomcat",
"EndpointID": "a4c384f17c6f8e443a430f130093ff6936bb59b1b54d0f056d1f0b4c703c1489",
"MacAddress": "02:42:ac:14:00:02",
"IPv4Address": "172.20.0.2/16",
"IPv6Address": ""
,
...
]
So it looks like, contrary to the author's statement, --net=container:myTomcat
and --net=myNetwork
keys have completely different meanings. The problem is I couldn't find any documentation on the --net=container:containerName
notation, so I'm not sure what exactly does it mean or how does it work. Does anyone have any insight on this?
docker docker-networking
add a comment
|
I'm reading the book "Docker and Kubernetes for Java Developers" by Jaroslaw Krochmalski, and I've stumbled upon the following example. The author proposes to create a bridged myNetwork
network and then run two containers (Apache Tomcat and BusyBox) attached to this network, as follows (the commands should be run in separate terminal sessions):
$ docker run -it --name myTomcat --net=myNetwork tomcat
$ docker run -it --net container:myTomcat busybox
The author specificaly says that "we want our busybox container to use the same network as Tomcat uses. As an alternative, we could of course go with specifying a network name explicitly, using the --net myNetwork
option".
Then the author proposes to check the communication between the containers by running the following command in the busybox container:
$ wget localhost:8080
This indeed worked, but immediately confused me, since we have two different containers, and it's not clear why do they communicate via localhost. Turns out, the above mentioned command with a --net container:myTomcat
key doesn't exactly add the container to the network, but makes it somehow visible under the same IP as the myTomcat
container.
This is confirmed by the observation that if you run docker network inspect myNetwork
, you will see that there's actually only one container attached to the network:
[
"Name": "myNetwork",
...
"Containers":
"464ed70a0c31784226dc943bcbcb79f7c4666b9d7825183706505731ac06a9bf":
"Name": "myTomcat",
"EndpointID": "a4c384f17c6f8e443a430f130093ff6936bb59b1b54d0f056d1f0b4c703c1489",
"MacAddress": "02:42:ac:14:00:02",
"IPv4Address": "172.20.0.2/16",
"IPv6Address": ""
,
...
]
On the contrary, if you run the busybox
container as follows:
$ docker run -it --net=myNetwork busybox
the visibility through localhost
won't work, but the docker network inspect myNetwork
will show both containers attached to the network under different IPs:
[
"Name": "myNetwork",
...
"Containers":
"41c607b78af36cf6512124b6c057ed31997ddd6067a99ae579fe25b53753178e":
"Name": "vigorous_clarke",
"EndpointID": "9bf6d6a294d885febcfe7f38e388f68af3f8bc7c0334c1dcea13512c3ead23d5",
"MacAddress": "02:42:ac:14:00:03",
"IPv4Address": "172.20.0.3/16",
"IPv6Address": ""
,
"464ed70a0c31784226dc943bcbcb79f7c4666b9d7825183706505731ac06a9bf":
"Name": "myTomcat",
"EndpointID": "a4c384f17c6f8e443a430f130093ff6936bb59b1b54d0f056d1f0b4c703c1489",
"MacAddress": "02:42:ac:14:00:02",
"IPv4Address": "172.20.0.2/16",
"IPv6Address": ""
,
...
]
So it looks like, contrary to the author's statement, --net=container:myTomcat
and --net=myNetwork
keys have completely different meanings. The problem is I couldn't find any documentation on the --net=container:containerName
notation, so I'm not sure what exactly does it mean or how does it work. Does anyone have any insight on this?
docker docker-networking
I've provided an answer here: Why would anyone use the same network namespace for two docker containers? which has link to documentation and possible uses.
– tgogos
Mar 28 at 14:18
If you are interested in learning more, I think you will have to dig more on linux processes and "network namespaces" which is what containers use under the hood. A nice video explaining a few things is this: There is No Such Thing as Container Networking - Kelsey Hightower, Google
– tgogos
Mar 28 at 14:20
1
@tgogos Thanks! That pretty much answers my question.
– Sergei Petunin
Mar 28 at 14:36
add a comment
|
I'm reading the book "Docker and Kubernetes for Java Developers" by Jaroslaw Krochmalski, and I've stumbled upon the following example. The author proposes to create a bridged myNetwork
network and then run two containers (Apache Tomcat and BusyBox) attached to this network, as follows (the commands should be run in separate terminal sessions):
$ docker run -it --name myTomcat --net=myNetwork tomcat
$ docker run -it --net container:myTomcat busybox
The author specificaly says that "we want our busybox container to use the same network as Tomcat uses. As an alternative, we could of course go with specifying a network name explicitly, using the --net myNetwork
option".
Then the author proposes to check the communication between the containers by running the following command in the busybox container:
$ wget localhost:8080
This indeed worked, but immediately confused me, since we have two different containers, and it's not clear why do they communicate via localhost. Turns out, the above mentioned command with a --net container:myTomcat
key doesn't exactly add the container to the network, but makes it somehow visible under the same IP as the myTomcat
container.
This is confirmed by the observation that if you run docker network inspect myNetwork
, you will see that there's actually only one container attached to the network:
[
"Name": "myNetwork",
...
"Containers":
"464ed70a0c31784226dc943bcbcb79f7c4666b9d7825183706505731ac06a9bf":
"Name": "myTomcat",
"EndpointID": "a4c384f17c6f8e443a430f130093ff6936bb59b1b54d0f056d1f0b4c703c1489",
"MacAddress": "02:42:ac:14:00:02",
"IPv4Address": "172.20.0.2/16",
"IPv6Address": ""
,
...
]
On the contrary, if you run the busybox
container as follows:
$ docker run -it --net=myNetwork busybox
the visibility through localhost
won't work, but the docker network inspect myNetwork
will show both containers attached to the network under different IPs:
[
"Name": "myNetwork",
...
"Containers":
"41c607b78af36cf6512124b6c057ed31997ddd6067a99ae579fe25b53753178e":
"Name": "vigorous_clarke",
"EndpointID": "9bf6d6a294d885febcfe7f38e388f68af3f8bc7c0334c1dcea13512c3ead23d5",
"MacAddress": "02:42:ac:14:00:03",
"IPv4Address": "172.20.0.3/16",
"IPv6Address": ""
,
"464ed70a0c31784226dc943bcbcb79f7c4666b9d7825183706505731ac06a9bf":
"Name": "myTomcat",
"EndpointID": "a4c384f17c6f8e443a430f130093ff6936bb59b1b54d0f056d1f0b4c703c1489",
"MacAddress": "02:42:ac:14:00:02",
"IPv4Address": "172.20.0.2/16",
"IPv6Address": ""
,
...
]
So it looks like, contrary to the author's statement, --net=container:myTomcat
and --net=myNetwork
keys have completely different meanings. The problem is I couldn't find any documentation on the --net=container:containerName
notation, so I'm not sure what exactly does it mean or how does it work. Does anyone have any insight on this?
docker docker-networking
I'm reading the book "Docker and Kubernetes for Java Developers" by Jaroslaw Krochmalski, and I've stumbled upon the following example. The author proposes to create a bridged myNetwork
network and then run two containers (Apache Tomcat and BusyBox) attached to this network, as follows (the commands should be run in separate terminal sessions):
$ docker run -it --name myTomcat --net=myNetwork tomcat
$ docker run -it --net container:myTomcat busybox
The author specificaly says that "we want our busybox container to use the same network as Tomcat uses. As an alternative, we could of course go with specifying a network name explicitly, using the --net myNetwork
option".
Then the author proposes to check the communication between the containers by running the following command in the busybox container:
$ wget localhost:8080
This indeed worked, but immediately confused me, since we have two different containers, and it's not clear why do they communicate via localhost. Turns out, the above mentioned command with a --net container:myTomcat
key doesn't exactly add the container to the network, but makes it somehow visible under the same IP as the myTomcat
container.
This is confirmed by the observation that if you run docker network inspect myNetwork
, you will see that there's actually only one container attached to the network:
[
"Name": "myNetwork",
...
"Containers":
"464ed70a0c31784226dc943bcbcb79f7c4666b9d7825183706505731ac06a9bf":
"Name": "myTomcat",
"EndpointID": "a4c384f17c6f8e443a430f130093ff6936bb59b1b54d0f056d1f0b4c703c1489",
"MacAddress": "02:42:ac:14:00:02",
"IPv4Address": "172.20.0.2/16",
"IPv6Address": ""
,
...
]
On the contrary, if you run the busybox
container as follows:
$ docker run -it --net=myNetwork busybox
the visibility through localhost
won't work, but the docker network inspect myNetwork
will show both containers attached to the network under different IPs:
[
"Name": "myNetwork",
...
"Containers":
"41c607b78af36cf6512124b6c057ed31997ddd6067a99ae579fe25b53753178e":
"Name": "vigorous_clarke",
"EndpointID": "9bf6d6a294d885febcfe7f38e388f68af3f8bc7c0334c1dcea13512c3ead23d5",
"MacAddress": "02:42:ac:14:00:03",
"IPv4Address": "172.20.0.3/16",
"IPv6Address": ""
,
"464ed70a0c31784226dc943bcbcb79f7c4666b9d7825183706505731ac06a9bf":
"Name": "myTomcat",
"EndpointID": "a4c384f17c6f8e443a430f130093ff6936bb59b1b54d0f056d1f0b4c703c1489",
"MacAddress": "02:42:ac:14:00:02",
"IPv4Address": "172.20.0.2/16",
"IPv6Address": ""
,
...
]
So it looks like, contrary to the author's statement, --net=container:myTomcat
and --net=myNetwork
keys have completely different meanings. The problem is I couldn't find any documentation on the --net=container:containerName
notation, so I'm not sure what exactly does it mean or how does it work. Does anyone have any insight on this?
docker docker-networking
docker docker-networking
asked Mar 28 at 14:11
Sergei PetuninSergei Petunin
4,0461 gold badge17 silver badges30 bronze badges
4,0461 gold badge17 silver badges30 bronze badges
I've provided an answer here: Why would anyone use the same network namespace for two docker containers? which has link to documentation and possible uses.
– tgogos
Mar 28 at 14:18
If you are interested in learning more, I think you will have to dig more on linux processes and "network namespaces" which is what containers use under the hood. A nice video explaining a few things is this: There is No Such Thing as Container Networking - Kelsey Hightower, Google
– tgogos
Mar 28 at 14:20
1
@tgogos Thanks! That pretty much answers my question.
– Sergei Petunin
Mar 28 at 14:36
add a comment
|
I've provided an answer here: Why would anyone use the same network namespace for two docker containers? which has link to documentation and possible uses.
– tgogos
Mar 28 at 14:18
If you are interested in learning more, I think you will have to dig more on linux processes and "network namespaces" which is what containers use under the hood. A nice video explaining a few things is this: There is No Such Thing as Container Networking - Kelsey Hightower, Google
– tgogos
Mar 28 at 14:20
1
@tgogos Thanks! That pretty much answers my question.
– Sergei Petunin
Mar 28 at 14:36
I've provided an answer here: Why would anyone use the same network namespace for two docker containers? which has link to documentation and possible uses.
– tgogos
Mar 28 at 14:18
I've provided an answer here: Why would anyone use the same network namespace for two docker containers? which has link to documentation and possible uses.
– tgogos
Mar 28 at 14:18
If you are interested in learning more, I think you will have to dig more on linux processes and "network namespaces" which is what containers use under the hood. A nice video explaining a few things is this: There is No Such Thing as Container Networking - Kelsey Hightower, Google
– tgogos
Mar 28 at 14:20
If you are interested in learning more, I think you will have to dig more on linux processes and "network namespaces" which is what containers use under the hood. A nice video explaining a few things is this: There is No Such Thing as Container Networking - Kelsey Hightower, Google
– tgogos
Mar 28 at 14:20
1
1
@tgogos Thanks! That pretty much answers my question.
– Sergei Petunin
Mar 28 at 14:36
@tgogos Thanks! That pretty much answers my question.
– Sergei Petunin
Mar 28 at 14:36
add a comment
|
1 Answer
1
active
oldest
votes
The --network=container:containerName
has the following meaning, according to the documentation:
With the network set to
container
a container will share the network stack of another container. [...] Example running a Redis container with Redis binding to localhost then running the redis-cli command and connecting to the Redis server over the localhost interface.$ docker run -d --name redis example/redis --bind 127.0.0.1
$ # use the redis container's network stack to access localhost
$ docker run --rm -it --network container:redis example/redis-cli -h 127.0.0.1
This is the reason the busybox
container can access the tomcat
application via http://localhost:8080
in the book example.
Thanks to @tgogos for pointing me in the right direction.
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399695%2fattaching-a-docker-container-to-another-containers-network-with-net-container%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The --network=container:containerName
has the following meaning, according to the documentation:
With the network set to
container
a container will share the network stack of another container. [...] Example running a Redis container with Redis binding to localhost then running the redis-cli command and connecting to the Redis server over the localhost interface.$ docker run -d --name redis example/redis --bind 127.0.0.1
$ # use the redis container's network stack to access localhost
$ docker run --rm -it --network container:redis example/redis-cli -h 127.0.0.1
This is the reason the busybox
container can access the tomcat
application via http://localhost:8080
in the book example.
Thanks to @tgogos for pointing me in the right direction.
add a comment
|
The --network=container:containerName
has the following meaning, according to the documentation:
With the network set to
container
a container will share the network stack of another container. [...] Example running a Redis container with Redis binding to localhost then running the redis-cli command and connecting to the Redis server over the localhost interface.$ docker run -d --name redis example/redis --bind 127.0.0.1
$ # use the redis container's network stack to access localhost
$ docker run --rm -it --network container:redis example/redis-cli -h 127.0.0.1
This is the reason the busybox
container can access the tomcat
application via http://localhost:8080
in the book example.
Thanks to @tgogos for pointing me in the right direction.
add a comment
|
The --network=container:containerName
has the following meaning, according to the documentation:
With the network set to
container
a container will share the network stack of another container. [...] Example running a Redis container with Redis binding to localhost then running the redis-cli command and connecting to the Redis server over the localhost interface.$ docker run -d --name redis example/redis --bind 127.0.0.1
$ # use the redis container's network stack to access localhost
$ docker run --rm -it --network container:redis example/redis-cli -h 127.0.0.1
This is the reason the busybox
container can access the tomcat
application via http://localhost:8080
in the book example.
Thanks to @tgogos for pointing me in the right direction.
The --network=container:containerName
has the following meaning, according to the documentation:
With the network set to
container
a container will share the network stack of another container. [...] Example running a Redis container with Redis binding to localhost then running the redis-cli command and connecting to the Redis server over the localhost interface.$ docker run -d --name redis example/redis --bind 127.0.0.1
$ # use the redis container's network stack to access localhost
$ docker run --rm -it --network container:redis example/redis-cli -h 127.0.0.1
This is the reason the busybox
container can access the tomcat
application via http://localhost:8080
in the book example.
Thanks to @tgogos for pointing me in the right direction.
answered Mar 28 at 15:16
Sergei PetuninSergei Petunin
4,0461 gold badge17 silver badges30 bronze badges
4,0461 gold badge17 silver badges30 bronze badges
add a comment
|
add a comment
|
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399695%2fattaching-a-docker-container-to-another-containers-network-with-net-container%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I've provided an answer here: Why would anyone use the same network namespace for two docker containers? which has link to documentation and possible uses.
– tgogos
Mar 28 at 14:18
If you are interested in learning more, I think you will have to dig more on linux processes and "network namespaces" which is what containers use under the hood. A nice video explaining a few things is this: There is No Such Thing as Container Networking - Kelsey Hightower, Google
– tgogos
Mar 28 at 14:20
1
@tgogos Thanks! That pretty much answers my question.
– Sergei Petunin
Mar 28 at 14:36