0

I'm trying to run through a few simple scenarios related to running .net core based applications in a Docker container. I'm running on Windows 10 and using VS 2015 for dev. I've installed the docker VS tools and Docker-Machine to allow me to use docker locally.

Using various tutorials online i've been able to:

  • Run the web api project locally from VS successfully
  • Install .net core on my 'default' docker machine (which has an IP of 192.168.99.100 that i obtained by running 'docker-machine inspect default')
  • Build a docker image containing my simple web api using VS
  • Expose port 5123 on the docker image

My issue is that even after the final step (which is detailed in different ways on multiple online tutorials) i am still unable to trigger a call to the web api when entering http://192.168.99.100:5123/api/values in a browser (I get a 'connection refused' error).

The config on my image indicates that the port exposure worked (I removed some fields that had null values):

{
        "Id": "675c3aa63600ae3db7fce0353f5e3e42a10a31d436c48b1d7f3b0aff0887f45c",
        "Created": "2016-09-05T16:55:04.917207712Z",
        "Path": "/bin/sh",
        "Args": [
            "-c",
            "dotnet CoreClr.Web.dll"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 10465,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2016-09-05T16:55:05.052990865Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },

        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,            
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                69,
                287
            ],
        },
        "GraphDriver": {
            "Name": "aufs",
            "Data": null
        },
        "Mounts": [],
        "Config": {
            "Hostname": "675c3aa63600",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": true,
            "AttachStderr": true,
            "ExposedPorts": {
                "5123/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "DOTNET_VERSION=1.0.0",
                "DOTNET_DOWNLOAD_URL=https://dotnetcli.blob.core.windows.net/dotnet/preview/Binaries/1.0.0/dotnet-debian-x64.1.0.0.tar.gz",
                "ASPNETCORE_URLS=http://*:5123"
            ],
            "Cmd": null,
            "Image": "username/coreclr.web",
            "Volumes": null,
            "WorkingDir": "/app",
            "Entrypoint": [
                "/bin/sh",
                "-c",
                "dotnet CoreClr.Web.dll"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "509cbf68bb9d642a71ca26380541ceee1c1b86ed886515b52a62e21aecb5ca94",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "5123/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/509cbf68bb9d",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "16e381f947d84f37040a71e81a213e31014ef8327176a2e18fab12da2c429b5c",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.11",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:0b",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "1eb481804e0a0f02ddaeca8e0868225b4d76795066fd0aedf950c83f8ee377fd",
                    "EndpointID": "16e381f947d84f37040a71e81a213e31014ef8327176a2e18fab12da2c429b5c",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.11",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:0b"
                }
            }
        }
    }

This is as far as the tutorials/samples that i found online went, and they didn't have this problem.

Any help or pointers appreciated.

Thanks

edit: added web.config

?xml version="1.0" encoding="utf-8"?>
<configuration>

  <!--
    Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
  -->

  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
  </system.webServer>
</configuration>

with the applications settings being:

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}
Alex Zevenbergen
  • 181
  • 1
  • 12
  • What does your app configuration look like? – DavidG Sep 05 '16 at 17:32
  • Added config contents to the main question - these are just the default values that were generated – Alex Zevenbergen Sep 05 '16 at 18:41
  • I'm no Docker expert, but doesn't the config say that the IP address is `172.17.0.11`? So does `http://172.17.0.11::5123/api/values` work? – DavidG Sep 06 '16 at 00:40
  • Hi @DavidG - i spotted that when i pasted the config here and tried it, but it was the same result. The one reference in these tutorials to the default docker container ip also had 192.168.99.100 so i'm uncertain what the 172 ip refers to. (I get a time out message when trying to connect to the 172 address which indicates there's nothing there) – Alex Zevenbergen Sep 06 '16 at 06:20

1 Answers1

0

Not entirely sure why this works, but starting the container with the 'dp' arguments set does:

$ docker run -dp 5123:5123/tcp --name=dev-api username/coreclr.web

The difference in the container config is that portbindings under the 'HostConfig' node has been set

"HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "5123/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "5123"
                    }
                ]
            },
Alex Zevenbergen
  • 181
  • 1
  • 12