Docker: Unable to connect to container from host

I try to use docker-compose in order to run an app which consists of 2 container: akka app and postgresql.
Here is yaml file:

version: "3"
services:
  api:
    image: akka-app:latest
    ports:
        - "9000:5000"
  db:
    image: postgres-db:latest

After the docker-compose up command I see that containers are up and running using docker ps command:

  • What server URL should one provide for TeamCity agent in Docker?
  • docker - can't connect to external postgres db
  • How to commit changed data in a mysql container to a new image
  • Docker dependency issue: Rake aborted! LoadError: cannot load such file — sqlite3/sqlite3_native
  • docker postgres data on build step
  • Why is this refresh token request to auth.docker.io returning a 404?
  • CONTAINER ID        IMAGE                                COMMAND                  CREATED             STATUS              PORTS                    NAMES
    65326e5a9677        akka-app:latest                      "java -cp /..."   40 minutes ago      Up 23 seconds       0.0.0.0:9000->5000/tcp   samplecompose_api_1
    1f86273c4f9a        postgres-db:latest                   "docker-ent..."   19 hours ago        Up 23 seconds       5432/tcp                 samplecompose_db_1
    

    But when I try to access the akka-app from the host via the GET request to 0.0.0.0:9000/status or localhost:9000/status I get back “refused to connect” error in the postman.

    Extra information:

    • Docker version 17.06.0-ce, build 02c1d87
    • docker-compose version
    • 1.14.0, build c7bdf9e MacOS Sierra 10.12.5

    Network settings of the akka-app container:

    "NetworkSettings": {
        "Bridge": "",
        "SandboxID": "5b5b322ffb0fb881317f8cb4e69b8fd887566b8c5b73940174aabace35d816f8",
        "HairpinMode": false,
        "LinkLocalIPv6Address": "",
        "LinkLocalIPv6PrefixLen": 0,
        "Ports": {
            "5000/tcp": [
                {
                    "HostIp": "0.0.0.0",
                    "HostPort": "9000"
                }
            ]
        },
        "SandboxKey": "/var/run/docker/netns/5b5b322ffb0f",
        "SecondaryIPAddresses": null,
        "SecondaryIPv6Addresses": null,
        "EndpointID": "",
        "Gateway": "",
        "GlobalIPv6Address": "",
        "GlobalIPv6PrefixLen": 0,
        "IPAddress": "",
        "IPPrefixLen": 0,
        "IPv6Gateway": "",
        "MacAddress": "",
        "Networks": {
            "pinpointcompose_default": {
                "IPAMConfig": null,
                "Links": null,
                "Aliases": [
                    "api",
                    "65326e5a9677"
                ],
                "NetworkID": "925c8379c6d5b334177d7d198d1d38e29983903474183bee5734df9d30ab9810",
                "EndpointID": "c7c37f545b00c6a19863315858e93a79f10b54b5675dc2cb8704d2f2f9b2bb1c",
                "Gateway": "172.18.0.1",
                "IPAddress": "172.18.0.2",
                "IPPrefixLen": 16,
                "IPv6Gateway": "",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "MacAddress": "02:42:ac:12:00:02"
            }
        }
    }
    

    UPDATE:

    docker-compose output:

    docker-compose up
    Starting samplecompose_api_1 ... 
    Starting samplecompose_api_1
    Starting samplecompose_db_1 ... 
    Starting samplecompose_api_1 ... done
    Attaching to samplecompose_db_1, samplecompose_api_1
    db_1   | LOG:  database system was shut down at 2017-07-06 08:54:56 UTC
    db_1   | LOG:  MultiXact member wraparound protections are now enabled
    api_1  | 09:04:26.030 [default-akka.actor.default-dispatcher-3] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
    api_1  | 09:04:27.472 [default-akka.actor.default-dispatcher-4] INFO sample-service - Bound to /0.0.0.0:5000
    

  • AWS opsworks docker service discovery
  • Docker Node.js environment variables
  • Supervisor & Docker: How to exit Supervisor if a service doesn't start?
  • Pull ssh keys in docker container at runtime
  • How to configure Docker for windows to push using hosts file for repository
  • Docker-compose container using host DNS server
  • One Solution collect form web for “Docker: Unable to connect to container from host”

    The problem was in an old VirtualBox installed who knows when on my laptop. So while it was installed I could not access running docker containers via localhost
    You can read more about this on official docker site

    After I uninstalled the VirtualBox from the laptop, then restarted the Docker app and relaunched the terminal sessions it was unreal to use localhost for access to the containers.

    Instead of the localhost I used the IP which I got from the docker-machine ip default. But this is not the good way.

    So ensure once again that you meet all of the requirements.

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