我创建了一个映像:stavalfi/projecty:latest
,它是一个非常基本的java spring应用程序。
当我运行一个没有蜂群的容器时,一切都很好:
docker run -d -p 8081:8080 --name container1 stavalfi/projecty:latest
使用铬:
http://localhost:8081/
http://172.17.0.2:8080/ <<-- the address of the leader (no other nodes in the swarm)
当我使用以下方法创建服务时:
docker service create -p 8080:8080 --name service1 stavalfi/projecty:latest
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ab8cb85e9750 stavalfi/projecty:latest "/bin/sh -c '/usr/..." 5 minutes ago Up 5 minutes 0.0.0.0:8081->8080/tcp container1
8928604253ed stavalfi/projecty:latest "/bin/sh -c '/usr/..." 21 minutes ago Up 21 minutes 8080/tcp service1.1.uhpsxn9mke7fkfwpgwke8ugnt
e312e148de87 nginx:latest "nginx -g 'daemon ..." 24 minutes ago Up 24 minutes 80/tcp web.1.zfihms3t4cy3h489srbfgrbw3
我无法打开我的容器,也无法从chrome访问我的应用程序:
http://localhost:8080/ <<-- no answer
http://10.0.2.15:8080/ <<-- response:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sat Oct 28 18:24:26 UTC 2017
There was an unexpected error (type=Internal Server Error, status=500).
8928604253ed: 8928604253ed: Name or service not known
http://10.0.2.15:8080/error <<-- response:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sat Oct 28 18:25:34 UTC 2017
There was an unexpected error (type=None, status=999).
No message available
我还通过运行以下命令创建了nginx:最新服务:
docker service create -p 80:80 --name web nginx
http://10.0.2.15:80/ <<-- working
http://localhost:80/ <<-- not working
java spring引导控制器代码:
@RestController
public class HelloController {
@RequestMapping("/")
@SneakyThrows
public String index() {
String hostname = InetAddress.getLocalHost().getHostName();
return "Hostname: "+hostname+ "! Greetings from Spring Boot!";
}
}
问题:
发布于 2017-10-28 21:15:09
我使用下面的命令打印正在运行的容器的日志(使用stavalfi/projecty:最新图像):
docker logs <docker container name/id>
我看到我的服务器找不到他的主机名,所以他处理了每个HTTP请求。奇怪的是,当我运行服务时,容器id并没有添加到/etc/host文件中,而是在运行容器时将containerID添加到/etc/host文件中。
如果有人知道的话我很想知道为什么。
https://stackoverflow.com/questions/46993188
复制相似问题