我使用 traefik 和 docker 设置的反向代理无法解析 Web 服务器地址

My reverse proxy setup with traefik and docker is not resolving web server address

我正在尝试使用 docker traefik. Here is my setup (I am trying to user this answer 设置反向代理):

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
cool-app            latest              3000cae089df        4 hours ago         927.2 MB
traefik             1.2.3-alpine        ea941f2b2800        3 weeks ago         46.91 MB
node                6.9                 cde8ba396275        3 months ago        658.6 MB

我用它来启动 trafik:

docker run --name traefik \
-p 80:80 \
-v /var/run/docker.sock:/var/run/docker.sock \
--network traefik \
traefik:1.2.3-alpine \
--entryPoints='Name:http Address::80' \
--docker \
--docker.watch 

这是开始我的网站:

docker run --name node_js \
--network traefik \
--label 'traefik.frontend.rule=Host:www.node-app.me' \
--label 'traefik.frontend.entryPoints=http' \
--label 'traefik.port=80' \
--label 'traefik.protocol=http' cool-app

两者都启动后,我的 docker ps 是

CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                NAMES
d00e0cf117fa        cool-app               "/bin/sh -c 'ng serve"   33 minutes ago      Up 33 minutes       80/tcp               node_js
5a6bd0b1c3c7        traefik:1.2.3-alpine   "/entrypoint.sh '--en"   35 minutes ago      Up 35 minutes       0.0.0.0:80->80/tcp   traefik

docker 检查网络部分是 cool-app :

"NetworkSettings": {
    "Bridge": "",
    "SandboxID": "7a549fc826b2c1d8d25917a374e519c90a93a91e863ffe825a69e41b36347875",
    "HairpinMode": false,
    "LinkLocalIPv6Address": "",
    "LinkLocalIPv6PrefixLen": 0,
    "Ports": {
        "80/tcp": null
    },
    "SandboxKey": "/var/run/docker/netns/7a549fc826b2",
    "SecondaryIPAddresses": null,
    "SecondaryIPv6Addresses": null,
    "EndpointID": "",
    "Gateway": "",
    "GlobalIPv6Address": "",
    "GlobalIPv6PrefixLen": 0,
    "IPAddress": "",
    "IPPrefixLen": 0,
    "IPv6Gateway": "",
    "MacAddress": "",
    "Networks": {
        "traefik": {
            "IPAMConfig": null,
            "Links": null,
            "Aliases": [
                "d00e0cf117fa"
            ],
            "NetworkID": "f8894d7c7cfdda1f3c4de805e0a6407aa0a3a5560e6c8c1c9505c12445027241",
            "EndpointID": "25b27deb775e16f26807845dead64a31e5d120ad9162523943d9ac8625283f6b",
            "Gateway": "172.18.0.1",
            "IPAddress": "172.18.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "MacAddress": "02:42:ac:12:00:03"
        }
    }
}

}

docker 检查网络部分是 traefik :

"NetworkSettings": {
    "Bridge": "",
    "SandboxID": "9b20b8465eb4cf3cbb85b082220ae90f76e8f6ba220d4c3b5f2b06c7149760c4",
    "HairpinMode": false,
    "LinkLocalIPv6Address": "",
    "LinkLocalIPv6PrefixLen": 0,
    "Ports": {
        "80/tcp": [
            {
                "HostIp": "0.0.0.0",
                "HostPort": "80"
            }
        ]
    },
    "SandboxKey": "/var/run/docker/netns/9b20b8465eb4",
    "SecondaryIPAddresses": null,
    "SecondaryIPv6Addresses": null,
    "EndpointID": "",
    "Gateway": "",
    "GlobalIPv6Address": "",
    "GlobalIPv6PrefixLen": 0,
    "IPAddress": "",
    "IPPrefixLen": 0,
    "IPv6Gateway": "",
    "MacAddress": "",
    "Networks": {
        "traefik": {
            "IPAMConfig": null,
            "Links": null,
            "Aliases": [
                "5a6bd0b1c3c7"
            ],
            "NetworkID": "f8894d7c7cfdda1f3c4de805e0a6407aa0a3a5560e6c8c1c9505c12445027241",
            "EndpointID": "4a39ccb693e1fdcdbf99937469029768f0542c1df71059f43bbf500c1ebc5b1d",
            "Gateway": "172.18.0.1",
            "IPAddress": "172.18.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "MacAddress": "02:42:ac:12:00:02"
        }
    }
}

}

Web 应用程序似乎已正确启动,但当我尝试访问时,我得到:

curl: (6) Could not resolve host: www.node-app.me

你能帮忙解决这个问题吗?

这是因为该域不存在,并且您没有为 curl 提供任何本地解析来知道去哪里。

要使其快速运行,您可以修改主机文件 (/etc/hosts):

127.0.0.1   localhost.localdomain   localhost www.node-app.me

另一种不修改主机文件的常用方法是利用 http://xip.io/