Can't connect to socket or published port from dotnet-monitor

Hi,
I have a dockerfile and docker-compose.yaml files to describe the main container and attached one.
When I run a container from the dockerfile alone everything is OK.
However, when I am running containers with docker-compose.yaml, I have an Error: socket hang up.

I am relatively new to containers and have some troubles to find the issue by myself.

Is it possible to get some help here?

Without seeing what you do differently with docker and docker-compose we could only guess. Please share how you start the container with the docker run command and docker compose. We should also see the compose file or at least the parts that are not secret. ONe difference is that Docker Compose uses “user-defined” networks and docker run just (by default) uses the default bridge (docker0).

Thank you!

My dockerfile

# syntax=docker/dockerfile:1

FROM mcr.microsoft.com/dotnet/sdk as build-env
WORKDIR /src
COPY src/*.csproj .
RUN dotnet restore
COPY src .
RUN dotnet publish -c Release -o /publish
FROM mcr.microsoft.com/dotnet/aspnet as runtime
WORKDIR /publish
COPY --from=build-env /publish .
EXPOSE 81
ENTRYPOINT ["dotnet", "myWebApp.dll"]

My compose.yml file:

services:
  web:
    build: .
    pull_policy: always
    environment: 
      ASPNETCORE_URLS: http://localhost:81
      COMPlus_EnableDiagnostics: 1
      DOTNET_EnableDiagnostics: 1
      DOTNET_DefaultDiagnosticPortSuspend: 0 
      DOTNET_DiagnosticPorts: /tmp/port.sock
      COMPOSE_HTTP_TIMEOUT: 1200
    expose:
      - 5000
    ports:
      - 5000:81
    volumes:
      - diagnostics:/tmp
  monitor:
    image: mcr.microsoft.com/dotnet/monitor
    depends_on:
      - web
    pull_policy: always
    environment: 
      ASPNETCORE_URLS: http://localhost:52323
      COMPlus_EnableDiagnostics: 1
      DOTNET_EnableDiagnostics: 1
      DOTNET_DefaultDiagnosticPortSuspend: 0 
      DotnetMonitor_DiagnosticPort_EndpointName: /tmp/port.sock
      DotnetMonitor_DiagnosticPort_ConnectionMode: listen
      DotnetMonitor_Storage_DumpTempFolder: /tmp/dumps
      DotnetMonitor_Urls: http://localhost:52323
      DotnetMonitor_Logging_Console_FormatterName: simple
      COMPOSE_HTTP_TIMEOUT: 1200
    entrypoint: dotnet-monitor
    command: ["collect", "--urls", "http://localhost:52323", "--metricUrls", "http://localhost:52325", "--no-auth"]
    expose:
      - 52323
      - 52325
    ports:
      - 52323:52323
      - 52325:52325
    volumes:
      - diagnostics:/tmp
      - dotnet-monitor-config:/etc/dotnet-monitor
volumes:
  diagnostics:
  dotnet-monitor-config:

In a couple of words: I am trying to connect sidecar container with dotnet-monitor to the container with the ASP
NET Core application.

So one of the container creates a unix domain socket inside a volume and the other container is supposed to use the same unix domain socket from the same volume?

I am not sure if there is more to it than making sure the “file” ownership and unix file permissions are set in both containers to permit the required access on the unix domain socket. It should work.

I assume you are aware this will only work if the containers run on the same host. With Swarm and Kubernetes deployments across nodes, you will require tcp sockets instead.

Furthermore, I modified your topic title from “Can’t get response from port” to “Can’t get response from unix domain socket”.

I have simplified the deployment.
I have created just dockerfile and compose.yml for the dotnet-monitor.

The dockerfile is:

FROM mcr.microsoft.com/dotnet/monitor as base
ENTRYPOINT [ "dotnet-monitor" ]
CMD ["collect", "--urls", "http://localhost:52323", "--metricUrls", "http://localhost:52325", "--no-auth"]

The compose.yml is:

services:
  dm:
    build: .
    ports:
     - 52323:52323
     - 52325:52325

It is important to mapping ports with compose! However, it looks like mapping doesn’t work!

Image inspection looks like this:

c:\AndyVG\__dev__\docker\dm>docker image inspect dm-dm
[
    {
        "Id": "sha256:79dedc13cff7f5d3dd50ff13376083034e83f44e6531f22ae5ba2a6020244908",
        "RepoTags": [
            "dm-dm:latest"
        ],
        "RepoDigests": [ ],
        "Parent": "",
        "Comment": "buildkit.dockerfile.v0",
        "Created": "2023-01-23T17:38:49.138287619Z",
        "Container": "",
        "ContainerConfig": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": null,
            "Cmd": null,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "DockerVersion": "",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/app:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "ASPNETCORE_URLS=",
                "DOTNET_RUNNING_IN_CONTAINER=true",
                "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true",
                "DOTNET_VERSION=7.0.2",
                "ASPNET_VERSION=7.0.2",
                "COMPlus_EnableDiagnostics=0",
                "DefaultProcess__Filters__0__Key=ProcessId",
                "DefaultProcess__Filters__0__Value=1",
                "DiagnosticPort__DeleteEndpointOnStartup=true",
                "DOTNET_gcServer=1",
                "Logging__Console__FormatterName=json",
                "Logging__Console__FormatterOptions__TimestampFormat=yyyy-MM-ddTHH:mm:ss.fffffffZ",
                "Logging__Console__FormatterOptions__UseUtcTimestamp=true"
            ],
            "Cmd": [
                "collect",
                "--urls",
                "http://localhost:52323",
                "--metricUrls",
                "http://localhost:52325",
                "--no-auth"
            ],
            "ArgsEscaped": true,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "/app",
            "Entrypoint": [
                "dotnet-monitor"
            ],
            "OnBuild": null,
            "Labels": {
                "com.docker.compose.project": "dm",
                "com.docker.compose.service": "dm",
                "com.docker.compose.version": "2.15.1"
            }
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 117205004,
        "VirtualSize": 117205004,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/f28f9ba9a21c17c565539cc8662dcf79fe70d6bcfd9a1cd3755a88ea9c54aec0/diff:/var/lib/docker/overlay2/8326a065fac8d53013ff1d769080184ac1eeb5bd66ac59a861e76db365107387/diff:/var/lib/docker/overlay2/61b710d96c6febc6f22d4b9d255d87b4320c43bb8ad3379ca74278138e32511d/diff:/var/lib/docker/overlay2/ff6a2f0e179127ec628c9d6355aeb135c2834c14eeb1abc8f31fa7be045e78a5/diff:/var/lib/docker/overlay2/1eb6d5f617a705261b750cbc32e9ad02cd322ce2c214d077a5287031b050f118/diff",
                "MergedDir": "/var/lib/docker/overlay2/829caf71246c1368cf5a0c231f7cc17387c0c0b139c399cc5b23d36682f97c48/merged",
                "UpperDir": "/var/lib/docker/overlay2/829caf71246c1368cf5a0c231f7cc17387c0c0b139c399cc5b23d36682f97c48/diff",
                "WorkDir": "/var/lib/docker/overlay2/829caf71246c1368cf5a0c231f7cc17387c0c0b139c399cc5b23d36682f97c48/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:8e012198eea15b2554b07014081c85fec4967a1b9cc4b65bd9a4bce3ae1c0c88",
                "sha256:7b3468b4ed0344ef91d56f8267897b28d6e8d83bfd26f0c8ebb9be5e401b2eeb",
                "sha256:542ffe8063ba6ac7812d8451c4954891cbd2ee1c1b8f8ef28abe9f926a17e534",
                "sha256:24e82a0995cfa8b5968a26fc90bdb07ef28186fa7391969af4e6a8b48ada32f5",
                "sha256:b36ea1fc58e3aa31f086d376a64de58863e68708cb2ca8c79f1c220e4de99ed2",
                "sha256:595b85c832815dd5bf714b3464d4d862cec4992187ef6e9201bf23c69a815868"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

c:\AndyVG\__dev__\docker\dm>

Please format your Dockerfile, compose file and the inspect output using “preformated text” blocks.

Actually, everything saved the formatting but when posted, the site didn’t show that.

Is there any documentation so I can learn how to do that?

Indeed there is:

Thank you!
I have formatted my code!

Btw. Now where I see you Windows path: it is always a good idea to mention that you use Docker Desktop for Windows. Without it, we assume it is Docker-CE on a Linux systems - at least I do. This is relevant as Docker Desktop does not behave like Docker-CE in each aspect.

That’s very unlikely. Share the output of docker ps and you will see the published ports are listed.

Though, I am not really sure why you shared the inspect output of the image. If it is because of the published port: this information is only available on the inspect output of the container.

Please share the output of the fresh started container until “Now listening on” appears. Also what are the parameters --urls and --metricUrls?

Sorry, next time I will specify the environment.

The start command for the dotnet-monitor is
dotnet-monitor collect --urls http://localhost:52323 --metricUrls http://localhost:52325 --no-auth

This is for the simplicity. dotnet-monitor will not set up SSL and don’t prompt for the user credentials. Also, it will return information through specified ports.

I am able to install the curl inside of the container and after I sent request to the http://localhost:52323/info, I had got the response.

But from the host I got

Error: socket hang up

The output is the next:

c:\AndyVG\__dev__\docker\dm>docker compose up
[+] Running 1/0
 - Container dm-dm-1  Created                                                                                                                                                                                                           0.0s
Attaching to dm-dm-1
dm-dm-1  | {"Timestamp":"2023-01-26T23:33:23.5195459Z","EventId":60,"LogLevel":"Information","Category":"Microsoft.Diagnostics.Tools.Monitor.Startup","Message":"Tell us about your experience with dotnet monitor: https://aka.ms/dotnet-monitor-survey","State":{"Message":"Tell us about your experience with dotnet monitor: https://aka.ms/dotnet-monitor-survey","link":"https://aka.ms/dotnet-monitor-survey","{OriginalFormat}":"Tell us about your experience with dotnet monitor: {link}"},"Scopes":[]}
dm-dm-1  | {"Timestamp":"2023-01-26T23:33:23.5333126Z","EventId":76,"LogLevel":"Information","Category":"Microsoft.Diagnostics.Tools.Monitor.Startup","Message":"Connection mode: Connect","State":{"Message":"Connection mode: Connect","{OriginalFormat}":"Connection mode: Connect"},"Scopes":[]}
dm-dm-1  | {"Timestamp":"2023-01-26T23:33:23.5359349Z","EventId":13,"LogLevel":"Warning","Category":"Microsoft.Diagnostics.Tools.Monitor.Startup","Message":"WARNING: Authentication has been disabled. This can pose a security risk and is not intended for production environments.","State":{"Message":"WARNING: Authentication has been disabled. This can pose a security risk and is not intended for production environments.","{OriginalFormat}":"WARNING: Authentication has been disabled. This can pose a security risk and is not intended for production environments."},"Scopes":[]}
dm-dm-1  | {"Timestamp":"2023-01-26T23:33:23.7645262Z","EventId":14,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now listening on: http://localhost:52323","State":{"Message":"Now listening on: http://localhost:52323","address":"http://localhost:52323","{OriginalFormat}":"Now listening on: {address}"},"Scopes":[]}
dm-dm-1  | {"Timestamp":"2023-01-26T23:33:23.7646721Z","EventId":14,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now listening on: http://localhost:52325","State":{"Message":"Now listening on: http://localhost:52325","address":"http://localhost:52325","{OriginalFormat}":"Now listening on: {address}"},"Scopes":[]}
dm-dm-1  | {"Timestamp":"2023-01-26T23:33:23.8040793Z","EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Application started. Press Ctrl\u002BC to shut down.","State":{"Message":"Application started. Press Ctrl\u002BC to shut down.","{OriginalFormat}":"Application started. Press Ctrl\u002BC to shut down."},"Scopes":[]}
dm-dm-1  | {"Timestamp":"2023-01-26T23:33:23.8058141Z","EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Hosting environment: Production","State":{"Message":"Hosting environment: Production","EnvName":"Production","{OriginalFormat}":"Hosting environment: {EnvName}"},"Scopes":[]}
dm-dm-1  | {"Timestamp":"2023-01-26T23:33:23.8059888Z","EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Content root path: /app/.store/dotnet-monitor/7.0.1/dotnet-monitor/7.0.1/tools/net7.0/any/","State":{"Message":"Content root path: /app/.store/dotnet-monitor/7.0.1/dotnet-monitor/7.0.1/tools/net7.0/any/","ContentRoot":"/app/.store/dotnet-monitor/7.0.1/dotnet-monitor/7.0.1/tools/net7.0/any/","{OriginalFormat}":"Content root path: {ContentRoot}"},"Scopes":[]}

Thank you for sharing the output, it allowed to see what I actually assumed: the application inside the container listens on localhost. Localhost inside a container is local to this particular container. It is not the same localhost as localhost of the host or another container.

Your process inside the container must listen on 0.0.0.0 in order to be reachable from outside.
I can’t help you with how to make the application listen on that port. That’s why I asked what the parameters --urls and --metricUrls do.

1 Like

Thank you so much!

After I have changed the initial command to:
dotnet-monitor collect --urls http://0.0.0.0:52323 --metricUrls http://0.0.0.0:52325 --no-auth

Everything started working just fine!