简体   繁体   中英

What is IP of bridge localhost for Docker?

I am dockerizing my application. I have two containers now. One of it wants to talk to another, in it's config I have "mongo": "127.0.0.1" I suppose they should talk through the bridge network:

$ docker network inspect bridge

[
   {
       "Name": "bridge",
       "Id": "f7ab26d71dbd6f557852c7156ae0574bbf62c42f539b50c8ebde0f728a253b6f",
       "Scope": "local",
       "Driver": "bridge",
       "IPAM": {
           "Driver": "default",
           "Config": [
               {
                   "Subnet": "172.17.0.1/16",
                   "Gateway": "172.17.0.1"
               }
           ]
       },
       "Containers": {},
       "Options": {
           "com.docker.network.bridge.default_bridge": "true",
           "com.docker.network.bridge.enable_icc": "true",
           "com.docker.network.bridge.enable_ip_masquerade": "true",
           "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
           "com.docker.network.bridge.name": "docker0",
           "com.docker.network.driver.mtu": "9001"
       },
       "Labels": {}
   }
]

Should I now change "mongo": "127.0.0.1" to "mongo": "0.0.0.0" ?

You can check a container IP.

$ docker inspect $(container_name) -f "{{json .NetworkSettings.Networks}}"

You can find IPAddress attribute from the output of json .

Yes, you should use a bridge network. The default "bridge" can be used but won't give you DNS resolution, check https://docs.docker.com/engine/userguide/networking/#user-defined-networks for details.

Best way to use is using with --link option to avoid to many changes.

for ex: --link mongo01:mongo it will instruct Docker to use the container named mongo01 as a linked container, and name it mongo inside your application container

So in your application you can use mongo:27017. without making any changes.

refer this for more details.

https://www.thachmai.info/2015/05/10/docker-container-linking-mongo-node/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM