如果这很有趣:操作系统:WIN10(cygwin),用Java编写的代码.
我以this为例.
I’d expect to reach the
service
in front of thecontainer
,which is running on port 80,usingmyvm1IP:80
(browser ir curl). Somehow this does not work. Or am I missunderstoonding the port mapping of the service?*:8080->80/tcp
我有一个正在运行的由2个节点组成的docker swarm集群.
我能够ping通两个正在运行的VM
我已经降级了版本,因为版本为issues with more recent version numbers.有关使用docker inspect vmName的引擎的信息:
"Engine": {
"EngineVersion": "18.06.1-ce","Labels": {
"provider": "hyperv"
},
我执行了以下docker-compose.yml:
version: "3"
services:
web:
image: elps/articleservice:1.1.0.4
deploy:
replicas: 2
restart_policy:
condition: on-failure
ports:
- "8080:80"
environment:
- MysqL_HOST=192.168.178.82
- MysqL_DB=article
- MysqL_USER=root
- MysqL_PASSWORD=abcdefg
networks:
- webnet
networks:
webnet:
两个副本均已成功启动,并且能够连接到本地正在运行的数据库(假设我查看了日志,并且一切正常.)容器已启动并正在运行.
Output of docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
979ed7ea88b7 elps/articleservice:1.1.0.4 "java -jar articlese…" 27 minutes ago Up 27 minutes 8080/tcp getstartedlab_web.1.j1j41so8pz6atxqnq9fqqquk7
7684c3667025 elps/articleservice:1.1.0.4 "java -jar articlese…" 27 minutes ago Up 27 minutes 8080/tcp getstartedlab_web.2.r4kadvztiwgpckkuannnhcsea
Output of docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
gvyi9moxtpvq getstartedlab_web replicated 2/2 elps/articleservice:1.1.0.4 *:8080->80/tcp
Output of docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
myvm1 * hyperv Running tcp://192.168.178.88:2376 v18.06.1-ce
myvm2 - hyperv Running tcp://192.168.178.89:2376 v18.06.1-ce
当我尝试执行curl myvmIP:80时,我收到了
Failed to connect to 192.168.178.88 port 80: Connection refused
>应用程序本身和容器在默认端口(8080)上运行
>服务器正在将端口8080上的传入流量重定向到容器端口80(显然没有运行)
在服务配置(docker-compose.yml)中切换端口后,它可以正常工作.
所以工作的docker-compose.yml看起来像这样:
version: "3"
services:
web:
image: elps/articleservice:1.1.0.4
deploy:
replicas: 2
restart_policy:
condition: on-failure
ports:
- "80:8080"
environment:
- MysqL_HOST=192.168.178.82
- MysqL_DB=article
- MysqL_USER=root
- MysqL_PASSWORD=abcdefg
networks:
- webnet
networks:
webnet:
因此,传入流量将按以下方式重定向:
Incoming traffic -> 80:
Service
->8080:Container