Docker:无法从主机

时间:2017-07-06 08:55:00

标签: docker docker-compose

我尝试使用docker-compose来运行一个包含2个容器的应用程序:akka app和postgresql。 这是yaml文件:

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

docker-compose up命令之后,我看到容器已启动并正在使用docker ps命令运行:

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

但是当我尝试通过GET请求从主机访问 akka-app 0.0.0.0:9000/statuslocalhost:9000/status时,我回来了#34;拒绝连接&# 34;邮递员的错误。

额外信息:

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

akka-app容器的网络设置:

"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"
        }
    }
}

更新

docker-compose输出:

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

1 个答案:

答案 0 :(得分:0)

问题出在安装的旧VirtualBox上,谁知道我的笔记本电脑何时出现。因此,在安装时,我无法通过localhost访问正在运行的docker容器... 您可以在官方泊坞网站上read more了解此信息

从笔记本电脑卸载VirtualBox后,重新启动Docker应用程序并重新启动终端会话,使用localhost来访问容器是不真实的。

我使用的是docker-machine ip default中使用的IP,而不是本地主机。但这不是好方法。

请再次确保您符合所有要求。