我正在尝试使用docker traefik设置反向代理。这是我的设置(我正在尝试用户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 inspect网络部分为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 inspect网络部分为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"
}
}
}
}
似乎网络应用程序正确启动,但当我尝试访问时,我得到了:
curl: (6) Could not resolve host: www.node-app.me
你能帮忙解决这个问题吗?
答案 0 :(得分:4)
这是因为该域名不存在,并且您没有为curl提供任何本地解析,无法知道去哪里。
为了让它快速运行,您可以修改主机文件(/ etc / hosts):
127.0.0.1 localhost.localdomain localhost www.node-app.me
另一种常见的方法是在不修改主机文件的情况下使用http://xip.io/