Running Docker for Windows, Error when exposing Ports

后端 未结 10 1551
天命终不由人
天命终不由人 2021-01-31 01:10

I am aware there are a lot of questions about running Docker on windows, however this question is about running the brand new Docker for Windows, on Windows.
In my case I am

10条回答
  •  暖寄归人
    2021-01-31 01:59

    If you are here because you have this issue in Visual Studio 2019:

    According to this post, the VS team is preparing a fix for this issue in 16.5 version, meanwhile, you can add the property "publishAllPorts": true in your launchSettings.json, for example:

    "Docker": {
          "commandName": "Docker",
          "launchBrowser": true,
          "launchUrl": "{Scheme}://{ServiceHost}:44374", #<== Set a fixed port
          "environmentVariables": {
            "ASPNETCORE_URLS": "https://+:44374;https://+:5000",
            "ASPNETCORE_HTTPS_PORT": "44374"
          },
          "publishAllPorts": true, #<== This is equivalent to the -P flag in 'docker run'
          "useSSL": true
        }
    

    Notice that the property "httpPort": XYZT is not defined. Having it defined will make the workaround not work.

    It worked for me with this setup:

    • Windows 10 1709 Build 16299.1747 with Fast Start OFF
    • Docker Desktop 2.2.05 (43884)
    • Docker Engine 19.03.8
    • Visual Studio 2019 Enterprise 16.5.4.
    • Microsoft.VisualStudio.Azure.Containers.Tools.Targets 1.10.8

    I realized that the command VS was creating, contained the -p parameter twice, one with the port I specified and another with port 80, like this: -p 3010:80 -p 3010:3010.

    After adding publishAllPorts it now creates the container and I can remotely debug it.

提交回复
热议问题