2017-09-08 195 views
0

我已經創建瞭如下的碼頭堆棧文件,它創建了3個服務,但是我無法訪問主機的外部。它也沒有創建任何端口。我創建了一個名爲test01的覆蓋網絡。當我通過命令行手動創建它時,它完美地工作。碼頭堆棧網絡問題

version: '3.0' 
networks: 
default: 
    external: 
    name: test01 
services: 
mssql: 
    image: microsoft/mssql-server-windows-developer 
    environment: 
    - SA_PASSWORD=Password1 
    - ACCEPT_EULA=Y 
    ports: 
    - 1433:1433 
    volumes: 
    - c:\Databases:c:\Databases 
    deploy: 
    placement: 
    constraints: [node.labels.os==Windows] 
web: 
    image: iiswithdb:latest 
    ports: 
    - 8080:8080 
    deploy: 
    replicas: 3 
lbs: 
    image: nginx:latest 
    ports: 
    - 80: 80 
    deploy: 
    placement: 
    constraints: [node.labels.os==Windows] 
+1

你如何運行堆棧?你使用了什麼命令? –

+0

碼頭堆棧命令我用來運行這個 – karthick

+0

運行堆棧後,docker network inspect test01的輸出是什麼? –

回答

0
c:\Program Files\docker>docker network inspect test01 
[ 
    { 
     "Name": "test01", 
     "Id": "8ffz8xihux13gx1uuhalub5by", 
     "Created": "2017-09-11T12:30:35.7747711+05:30", 
     "Scope": "swarm", 
     "Driver": "overlay", 
     "EnableIPv6": false, 
     "IPAM": { 
      "Driver": "default", 
      "Options": null, 
      "Config": [ 
       { 
        "Subnet": "10.0.0.0/24", 
        "Gateway": "10.0.0.1" 
       } 
      ] 
     }, 
     "Internal": false, 
     "Attachable": false, 
     "Ingress": false, 
     "ConfigFrom": { 
      "Network": "" 
     }, 
     "ConfigOnly": false, 
     "Containers": { 
      "2f283e7c21608d09a57a7cdef25a836d77c0ceb8030ae15796ff692e43b0eb73": { 
       "Name": "test_web.1.jti1pyrgxv3v4yet9m9cpk0i4", 
       "EndpointID": "bed2a5e0d077fcf48ab2d6fe419a8a69a45c3033e1a8602cf6395f93bec405b8", 
       "MacAddress": "00:15:5d:f3:aa:1a", 
       "IPv4Address": "10.0.0.5/24", 
       "IPv6Address": "" 
      }, 
      "8c55fad8ad54e5286bb7fc54da52ad1958854bceacbf0260400e7dc3c00c1c45": { 
       "Name": "test_mssql.1.mn31bwoh8iwg5sge5rllh7gc9", 
       "EndpointID": "00c6e68d6a22ee0dc5ad90cda7ab958323a0b07206ce4583f11baa8b3476de8f", 
       "MacAddress": "00:15:5d:f3:aa:23", 
       "IPv4Address": "10.0.0.3/24", 
       "IPv6Address": "" 
      } 
     }, 
     "Options": { 
      "com.docker.network.driver.overlay.vxlanid_list": "4097", 
      "com.docker.network.windowsshim.hnsid": "b76fa7e3-530d-4133-b72a-1d1818cd3c16" 
     }, 
     "Labels": {}, 
     "Peers": [ 
      { 
       "Name": "node2-f3dedf0e26d9", 
       "IP": "10.30.50.10" 
      }, 
      { 
       "Name": "node3-2e1ad7fb91be", 
       "IP": "10.30.50.13" 
      } 
     ] 
    } 

]

下面是輸出

c:\Program Files\docker>docker service ls 
ID     NAME    MODE    REPLICAS   IMAGE            PORTS 
bo9uovidd4z3  test_web   replicated   3/3     iiswithdb:latest         *:8080->8080/tcp 
sujwg53gjnp3  test_lbs   replicated   0/1     nginx:latest          *:80->80/tcp 
vyxyoaji8jkd  test_mssql   replicated   1/1     microsoft/mssql-server-windows-developer:latest *:1433->1433/tcp 

c:\Program Files\docker>docker service ps test_mssql 
ID     NAME    IMAGE            NODE    DESIRED STATE  CURRENT STATE   ERROR    PORTS 
mn31bwoh8iwg  test_mssql.1  microsoft/mssql-server-windows-developer:latest node2    Running    Running 6 minutes ago 

當我檢查SQL服務器容器我無法找到任何端口功能標籤

c:\Program Files\docker>docker service ps test_lbs 
ID     NAME    IMAGE    NODE    DESIRED STATE  CURRENT STATE   ERROR    PORTS 
j4x806u1ucdr  test_lbs.1   nginx:latest       Running    Pending 32 minutes ago 

c:\Program Files\docker>docker service ps test_web 
ID     NAME    IMAGE    NODE    DESIRED STATE  CURRENT STATE   ERROR        PORTS 
jti1pyrgxv3v  test_web.1   iiswithdb:latest node2    Running    Running 22 minutes ago 
1gudznmi9ufz   \_ test_web.1  iiswithdb:latest node2    Shutdown   Failed 27 minutes ago "task: non-zero exit (21479434…" 
xxkr98na4qsy  test_web.2   iiswithdb:latest node3    Running    Running 29 minutes ago 
7j1y6vc90qvf  test_web.3   iiswithdb:latest node3    Running    Running 29 minutes ago 
0
C:\Users\Administrator>docker service ls 
ID     NAME    MODE    REPLICAS   IMAGE            PORTS 
19qeljqt3wuf  test_mssql   replicated   1/1     microsoft/mssql-server-windows-developer:latest *:1433->1433/tcp 
48gamfl4j4rl  test_web   replicated   3/3     iiswithdb:latest         *:8080->8080/tcp 
nxycxrigmz4u  test_lbs   replicated   1/1     nginx:latest          *:80->80/tcp 

C:\Users\Administrator>docker service ps test_lbs 
ID     NAME    IMAGE    NODE    DESIRED STATE  CURRENT STATE   ERROR    PORTS 
81fm4xplekig  test_lbs.1   nginx:latest  node2    Running    Running 25 minutes ago 

C:\Users\Administrator>docker service ps test_web 
ID     NAME    IMAGE    NODE    DESIRED STATE  CURRENT STATE    ERROR        PORTS 
aivzt7eagf4f  test_web.1   iiswithdb:latest node1    Running    Running about an hour ago 
sny1zf7osibq  test_web.2   iiswithdb:latest node2    Running    Running about an hour ago 
lwzlpaks1b4t   \_ test_web.2  iiswithdb:latest node2    Shutdown   Failed about an hour ago "task: non-zero exit (21479434…" 
iav5mxqdbzoy  test_web.3   iiswithdb:latest node3    Running    Running about an hour ago 

C:\Users\Administrator>docker service ps test_mssql 
ID     NAME    IMAGE            NODE    DESIRED STATE  CURRENT STATE   ERROR    PORTS 
pfu8qyw7vqxp  test_mssql.1  microsoft/mssql-server-windows-developer:latest node2    Running    Running 26 minutes ago      
1

您的服務需要明確加入您定義的網絡。您可以在撰寫文件中執行此操作。否則,他們將使用由堆棧/撰寫創建的默認網絡。 https://docs.docker.com/compose/compose-file/#networks

+0

我已經嘗試過,但沒有成功仍然沒有創建端口。對於我提到的每個服務都像網絡: - test01 – karthick

+0

我可以訪問主機內的容器。但我不能從外面。有沒有n/w的東西? – karthick