Skip to content

WebSocket connection can't be established while in Docker container #107

@iTKerry

Description

@iTKerry

Describe the bug
I packed an ASP.NET application that consumes HuobiSocketClient into Docker image and hosted it locally using docker-compose. The same code works well outside of Docker. Also, REST API forks well from Docker. The issue is only with WSS connection.

Same approach work successfully with other exchanges from CryptoExchange.Net EXCEPT: Huobi, Kucoin, OKX

To Reproduce

Just try to establish socket connection from Docker container.

docker-compose.yml

  huobi.server:
    container_name: huobi.server
    build:
      context: .
      dockerfile: ./MyProjectName/Dockerfile
    ports:
      - "5006:5006"
    environment:
      - "ASPNETCORE_ENVIRONMENT=Production"
      - "ASPNETCORE_URLS=http://+:5006"
    networks:
      - customNetwork

Some code from program.cs

var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(5006, o => o.Protocols = HttpProtocols.Http1AndHttp2AndHttp3));

var app = builder.Build();
app.UseWebSockets();
app.Run();

Expected behavior
Connection should be established successfully.

Debug logging
Error while establishing connection:
{"Code":null,"Message":"Can't connect to the server","Data":null}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions