我使用windows容器并尝试创建docker swarm,我创建三个虚拟机使用hyper-v,每个操作系统都是windows server 2016.There机器ip是:
windocker211 192.168.1.211
windocker212 192.168.1.212
windocker219 192.168.1.219
docker swarm节点是:
PS C:\ConsoleZ> docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
4c0g0o0uognheugw4do1a1h7y windocker212 Ready Active
bbxot0c8zijq7xw4lm86svgwp * windocker219 Ready Active Leader
wftwpiqpqpbqfdvgenn787psj windocker211 Ready Active
我创建了使用命令:
docker service create --name=demo5 -p 5005:5005 --replicas 6 192.168.1.245/cqgis/wintestcore:0.6
docker镜像是asp.net核心应用程序,Dockerfile是:
FROM 192.168.1.245/win/aspnetcore-runtime:1.1.2
COPY . /app
WORKDIR /app
ENV ASPNETCORE_URLS http://*:5005
EXPOSE 5005/tcp
ENTRYPOINT ["dotnet", "dotnetcore.dll"]
然后它创造了成功:
PS C:\ConsoleZ> docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
omhu7e0vo96s demo5 replicated 6/6 192.168.1.245/cqgis/wintestcore:0.6 *:5005->5005/tcp
PS C:\ConsoleZ> docker service ps demo5
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
8pihnak9a2ei demo5.1 192.168.1.245/cqgis/wintestcore:0.6 windocker212 Running Running 59 seconds ago
ut3f3b9giu4w demo5.2 192.168.1.245/cqgis/wintestcore:0.6 windocker219 Running Running 47 seconds ago
iy1xjevt67yl demo5.3 192.168.1.245/cqgis/wintestcore:0.6 windocker211 Running Running about a minute ago
q7f1gnbwslr3 demo5.4 192.168.1.245/cqgis/wintestcore:0.6 windocker212 Running Running about a minute ago
8zewaktcu32h demo5.5 192.168.1.245/cqgis/wintestcore:0.6 windocker219 Running Running about a minute ago
xq820kqwf3v9 demo5.6 192.168.1.245/cqgis/wintestcore:0.6 windocker211 Running Running 55 seconds ago
但我的问题是我无法通过
访问网站http://192.168.1.219:5005/
http://192.168.1.219:5005/
http://192.168.1.219:5005/
当我使用命令
时docker run -it -p 5010:5005 192.168.1.245/cqgis/wintestcore:0.6
我可以使用http://192.168.1.219:5010/
获得正确的结果
我的码头信息是
PS C:\ConsoleZ> docker info
Containers: 4
Running: 3
Paused: 0
Stopped: 1
Images: 5
Server Version: 17.06.0-ce-rc1
Storage Driver: windowsfilter
Windows:
Logging Driver: json-file
Plugins:
Volume: local
Network: l2bridge l2tunnel nat null overlay transparent
Log: awslogs etwlogs fluentd json-file logentries splunk syslog
Swarm: active
NodeID: bbxot0c8zijq7xw4lm86svgwp
Is Manager: true
ClusterID: 32vsgwrbn6ihvpevly71gkgxk
Managers: 1
Nodes: 3
Orchestration:
Task History Retention Limit: 5
Raft:
Snapshot Interval: 10000
Number of Old Snapshots to Retain: 0
Heartbeat Tick: 1
Election Tick: 3
Dispatcher:
Heartbeat Period: 5 seconds
CA Configuration:
Expiry Duration: 3 months
Force Rotate: 0
Root Rotation In Progress: false
Node Address: 192.168.1.219
Manager Addresses:
192.168.1.219:2377
Default Isolation: process
Kernel Version: 10.0 14393 (14393.1198.amd64fre.rs1_release_sec.170427-1353)
Operating System: Windows Server 2016 Datacenter
OSType: windows
Architecture: x86_64
CPUs: 8
Total Memory: 2.89GiB
Name: windock219
ID: 7AOY:OT6V:BTJV:NCHA:3OF5:5WR5:K2YR:CFG3:VXLD:QTMD:GA3D:ZFJ2
Docker Root Dir: C:\ProgramData\docker
Debug Mode (client): false
Debug Mode (server): true
File Descriptors: -1
Goroutines: 297
System Time: 2017-06-04T19:58:20.7582294+08:00
EventsListeners: 2
Registry: https://index.docker.io/v1/
Experimental: true
Insecure Registries:
192.168.1.245
127.0.0.0/8
Live Restore Enabled: false
答案 0 :(得分:1)
Docker for Windows容器和Docker for Linux之间的网络存在一些差异。 Windows Containers使用HyperV网络技术提供docker使用的虚拟网络功能。从某些限制开始,这些限制不像您期望的那样,或者可能在标准Docker文档中找到。
使用此脚本,您可以删除所有虚拟网络设置:
Stop-Service docker
Get-ContainerNetwork | Remove-ContainerNetwork
Get-NetNat | Remove-NetNat
Get-VMSwitch | Remove-VMSwitch
Start-Service docker
答案 1 :(得分:1)
我相信你需要在" host"中发布端口。模式(docs.microsoft.com/en-us/virtualization/windowscontainers / ...)。此外,它将是运行容器和主机之间的一对一端口映射,因此您将无法在同一端口上运行多个容器。路由网格尚未在Windows上运行。
答案 2 :(得分:0)
由于limitation of the WinNAT networking,您无法从同一台计算机访问容器的已发布端口。但是您可以使用外部请求到达所需的端口。
在您的示例中,从{strong> 192.168.1.219
以外的计算机,使用URL http://192.168.1.219:5005/
的访问将成功。如果请求来自那些机器之外,则URL的http://192.168.1.211:5005/
和http://192.168.1.212:5005/
也将成功。
使用“主机”模式将成功:但是,您没有利用“路由网格”功能的优势,该功能允许从任何服务节点(仅从一个节点)访问该服务。 / p>