Run multiple containers on same docker network localhost

I want to connect from my app to mongodb on localhost, so they need to have same localhost address.

So the question is: Can two containers share they localhost, or for each container the localhost ip must be different?

  • Dotnet Core publish to IIS from Mac
  • Atomic OS/Core OS for large scale Mesos cluster?
  • Keeping environment variables on window split
  • Specify bolt port for a neo4j docker container
  • Docker: communication between web container and php container
  • How to remove development dependencies in production docker images
  • I’m doing this for test environment purposes, so I don’t want in-memory database, changed mongo uri or any different solution. I just want to connect from A to B by localhost.

    To run my network and containers i type:

    docker network create --driver bridge isolated_nw
    docker run --name mongodb -d -p 27017:27017 --network=isolated_nw mongo:3.4.2
    docker run --name roomate-profiles --network=isolated_nw -d -p 8080:8080 sovas/roomate-profiles

    My custom docker network:

            "Name": "isolated_nw",
            "Id": "3efd6831784c2a8c9e9ea345144fcc6b9180e70c0e1b4b5d1a72219051b24e67",
            "Scope": "local",
            "Driver": "bridge",
            "EnableIPv6": false,
            "IPAM": {
                "Driver": "default",
                "Options": {},
                "Config": [
                        "Subnet": "",
                        "Gateway": ""
            "Internal": false,
            "Containers": {
                "57d4e2fb1f0c8d776329fd6ce82e5905df00e261ab6923595578dcb35913b03e": {
                    "Name": "roomate-profiles",
                    "EndpointID": "5a8158dc1aba6958218d1cca3c98ca911ab2cfa73be839ceece2e7819b244c91",
                    "MacAddress": "02:42:ac:12:00:03",
                    "IPv4Address": "",
                    "IPv6Address": ""
                "8fa815735d7ebb77434f8abf11e58f18faeb5d67e2743903d81f4600bd558c35": {
                    "Name": "mongodb",
                    "EndpointID": "7b7a7ed1ad08bbe381fb6d66c6e9fea66ee9b7c581f530bdf4d82f0741bff04b",
                    "MacAddress": "02:42:ac:12:00:02",
                    "IPv4Address": "",
                    "IPv6Address": ""
            "Options": {},
            "Labels": {}


  • Is it possible to execute CMD at the middle of docker file?
  • Get docker-compose.yml file location from running container?
  • Connectivity from microservice on host out of docker-compose network
  • Pulling and building io.js from source using a specific version
  • How can I connect to a server using python sockets inside a Docker container?
  • How to push container to Google Container Registry (unable to create repository)
  • One Solution collect form web for “Run multiple containers on same docker network localhost”

    localhost won’t work since it refers to the roomate-profiles container. But you can do

    since both containers are connected to the same network. There is also no need to map the mongodb port to the host (unless you need it for something else).

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.