代码之家  ›  专栏  ›  技术社区  ›  Pylyp Lebediev

docker compose无法连接到asp。净核心站点

  •  1
  • Pylyp Lebediev  · 技术社区  · 6 年前

    我正在尝试运行docker compose for ASP。NET核心应用程序根据 https://docs.docker.com/get-started/part3 在Windows Server 2016上。

    Docker文件

    FROM microsoft/aspnetcore-build:2.0 AS build-env
    WORKDIR /app
    EXPOSE 80
    
    # Copy csproj and restore as distinct layers
    COPY *.csproj ./
    RUN dotnet restore
    
    # Copy everything else and build
    COPY . ./
    RUN dotnet publish -c Release -o out
    
    # Build runtime image
    FROM microsoft/aspnetcore:2.0
    WORKDIR /app
    COPY --from=build-env /app/out .
    ENTRYPOINT ["dotnet", "Community.dll"]
    

    docker编写。yml公司

    version: "3"
    services:
      web:
        image: linuxchata/community-app:v1
        deploy:
          replicas: 1
          resources:
            limits:
              memory: 500M
          restart_policy:
            condition: on-failure
        ports:
          - "80:4000"
        networks:
          - webnet
    networks:
      webnet:
    

    已通过运行以下命令创建服务

    docker stack deploy -c docker-compose.yml community
    

    docker service ls命令

    ID                  NAME                MODE                REPLICAS            IMAGE                         PORTS
    t5jsy98xkl5p        community_web       replicated          1/1                 linuxchata/community-app:v1   *:80->4000/tcp
    

    http://127.0.0.1:4000/ ,则, http://localhost:4000/ http://servername:4000/ 无法通过浏览器访问。但是,运行单个容器的效果与预期一样(通过docker run命令)。

    你能告诉我这里可能有什么问题吗?更多详情如下。

    docker版本命令

    Client:
     Version:       18.03.0-ce
     API version:   1.37
     Go version:    go1.9.4
     Git commit:    0520e24
     Built: Wed Mar 21 23:06:28 2018
     OS/Arch:       windows/amd64
     Experimental:  false
     Orchestrator:  swarm
    
    Server:
     Engine:
      Version:      18.03.0-ce
      API version:  1.37 (minimum version 1.24)
      Go version:   go1.9.4
      Git commit:   0520e24
      Built:        Wed Mar 21 23:21:06 2018
      OS/Arch:      windows/amd64
      Experimental: false
    

    docker info命令

    Containers: 7
     Running: 1
     Paused: 0
     Stopped: 6
    Images: 24
    Server Version: 18.03.0-ce
    Storage Driver: windowsfilter
     Windows:
    Logging Driver: json-file
    Plugins:
     Volume: local
     Network: ics l2bridge l2tunnel nat null overlay transparent
     Log: awslogs etwlogs fluentd gelf json-file logentries splunk syslog
    Swarm: active
     NodeID: kdeu85ro38qhzffzo58ck9c2x
     Is Manager: true
     ClusterID: agtu0rm8l10rwkuoqlt6fdtzs
     Managers: 1
     Nodes: 1
     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
     Autolock Managers: false
     Root Rotation In Progress: false
     Node Address: 10.0.0.5
     Manager Addresses:
      10.0.0.5:2377
    Default Isolation: process
    Kernel Version: 10.0 14393 (14393.2125.amd64fre.rs1_release.180301-2139)
    Operating System: Windows Server 2016 Datacenter
    OSType: windows
    Architecture: x86_64
    CPUs: 2
    Total Memory: 8GiB
    Name: Server2016
    ID: MPSV:4IF7:K6LN:FD2L:U4U4:OAW6:4JSQ:RDCK:JN3G:BZQF:24AW:5EII
    Docker Root Dir: C:\ProgramData\Docker
    Debug Mode (client): false
    Debug Mode (server): true
     File Descriptors: -1
     Goroutines: 16604
     System Time: 2018-05-16T19:56:26.9114443Z
     EventsListeners: 2
    Registry: https://index.docker.io/v1/
    Labels:
    Experimental: false
    Insecure Registries:
     127.0.0.0/8
    Live Restore Enabled: false
    

    docker network inspect community\u webnet命令

    [
        {
            "Name": "community_webnet",
            "Id": "n2rk9sh5ialmdg5x0s4k10q5y",
            "Created": "2018-05-16T19:15:39.8464593Z",
            "Scope": "swarm",
            "Driver": "overlay",
            "EnableIPv6": false,
            "IPAM": {
                "Driver": "default",
                "Options": null,
                "Config": [
                    {
                        "Subnet": "10.0.1.0/24",
                        "Gateway": "10.0.1.1"
                    }
                ]
            },
            "Internal": false,
            "Attachable": false,
            "Ingress": false,
            "ConfigFrom": {
                "Network": ""
            },
            "ConfigOnly": false,
            "Containers": {
                "c4fcafb9f810c95769c6456b7a3d0e0ac6b398672468b86e07d0d76981665ddd": {
                    "Name": "community_web.1.4lijwfo1g0wi1kdxf87i01nx4",
                    "EndpointID": "2272330e9dbebbd5eead54d3d476354c79d94dc2d363c8d44560acc4c5128627",
                    "MacAddress": "00:15:5d:48:8f:d9",
                    "IPv4Address": "10.0.1.15/24",
                    "IPv6Address": ""
                },
                "community_webnet-sbox": {
                    "Name": "community_webnet-endpoint",
                    "EndpointID": "9f6d2cd49c4aad73c7d82432d654cd202dd550956d6857378737a358eba7b8b1",
                    "MacAddress": "00:15:5d:48:8b:ac",
                    "IPv4Address": "10.0.1.2/24",
                    "IPv6Address": ""
                }
            },
            "Options": {
                "com.docker.network.driver.overlay.vxlanid_list": "4102",
                "com.docker.network.windowsshim.hnsid": "64b76ba8-f0de-4516-aaa8-952855cbd1da"
            },
            "Labels": {
                "com.docker.stack.namespace": "community"
            },
            "Peers": [
                {
                    "Name": "d3045df8c95e",
                    "IP": "10.0.0.5"
                }
            ]
        }
    ]
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Pylyp Lebediev    5 年前

    正确的docker撰写文件

    version: "3.5"
    
    services:
      web:
        image: linuxchata/community-app:v1
        restart: on-failure
        ports:
          - "4000:80"
        networks:
          - webnet
    networks:
      webnet:
    

    运行docker compose的命令 docker-compose -f docker-compose.yml up -d