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;








2















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?










share|improve this question
























  • 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

















2















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?










share|improve this question
























  • 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













2












2








2


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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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

















  • 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












1 Answer
1






active

oldest

votes


















1
















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.






share|improve this answer
























    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
    );



    );














    draft saved

    draft discarded
















    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









    1
















    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.






    share|improve this answer





























      1
















      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.






      share|improve this answer



























        1














        1










        1









        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        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





















            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.




















            draft saved

            draft discarded















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현