Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ocelot Issue while host in docker #1662

Closed
Shonzon opened this issue May 30, 2023 · 8 comments
Closed

Ocelot Issue while host in docker #1662

Shonzon opened this issue May 30, 2023 · 8 comments
Assignees
Labels
invalid Not actually an issue wontfix No plan to include this issue in the Ocelot core functionality.

Comments

@Shonzon
Copy link

Shonzon commented May 30, 2023

After Hosted in Docker Ocelot did not invoke microservices properly : (getting error)
Ocelot.Responder.Middleware.ResponderMiddleware[0]
requestId: 0HMR0TMTEM44N:00000003, previousRequestId: no previous request id, message: Error Code: ConnectionToDownstreamServiceError Message: Error connecting to downstream service, exception: System.Net.Http.HttpRequestException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (marketservice:7216)
---> System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Ocelot File :
{
"Routes": [
{
"DownstreamPathTemplate": "/api/Authenticate/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7217
}
],
"UpstreamPathTemplate": "/api/Authenticate/{everything}",
"UpstreamHttpMethod": [ "POST", "GET" ]
},
{
"DownstreamPathTemplate": "/api/AmountModels/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7217
}
],
"UpstreamPathTemplate": "/api/AmountModels/{everything}",
"UpstreamHttpMethod": [ "POST", "GET" ]
},
],
"GlobalConfiguration": {
"BaseUrl": "http://apigateway:7215/"
},
"LoadBalancerOptions": {
"Type": "LeastConnection"
}
}

Docker Compose file :
version: '3.4'

services:
marketservice:
image: ${DOCKER_REGISTRY-}marketservice
build:
context: .
dockerfile: MarketServices\Dockerfile
args:
- PROJECT=MarketServices/MarketServices.csproj
ports:
- 7216:80
environment:
- CONFIG_SERVICE_URL=file:C:\app\Shared\appsettings.shared.json
volumes:
- ./Shared:C:\app\Shared
networks:
- mynetwork

apigateway:
image: ${DOCKER_REGISTRY-}apigateway
build:
context: .
dockerfile: APIGateway\Dockerfile
args:
- PROJECT=APIGateway/APIGateway.csproj
environment:
- CONFIG_SERVICE_URL=file:C:\app\Shared\appsettings.shared.json
ports:
- 7215:80
volumes:
- ./Shared:C:\app\Shared
networks:
- mynetwork

authenticationservice:
image: ${DOCKER_REGISTRY-}authenticationservice
build:
context: .
dockerfile: AuthenticationService\Dockerfile
args:
- PROJECT=AuthenticationService/AuthenticationService.csproj
ports:
- 7217:80
environment:
- CONFIG_SERVICE_URL=file:C:\app\Shared\appsettings.shared.json
volumes:
- ./Shared:C:\app\Shared
networks:
- mynetwork

@raman-m
Copy link
Member

raman-m commented May 30, 2023

Dear @Shonzon,

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (marketservice:7216)

By other words, gateway cannot connect to the service behind the docker container ingress.
You must place all ASP.NET projects of the services including the gateway app into configs of Docker Compose project in Visual Studio! So, you need to create Docker network for Docker engine to register all services in this network to be visible for all services of the Docker Compose project.
Otherwise all network communication between services being deployed into Docker container will fail.
Or you should consider deployment to public cloud services like Amazon Lambda or Azure Functions.


System.Net.Sockets.SocketException (10060):

I do not recommend to use ws-protocol for versions 17-19. You can try to route ws-traffic by Ocelot v15-16 for .NET 3.1.
Current v19 (and 18, 17, etc.) doesn't support wss-protocol at all!

@raman-m
Copy link
Member

raman-m commented May 30, 2023

Please, use the issue template while creating an issue via pressing the New Issue button!
Examples of bugs: #1636, #1660, #1590. Examples of features: #1637, #1400

Because you create a bug, you need to:

  • specify Expected & Actual behavior.
  • share details in "Steps to Reproduce the Problem"!

Also, you need to give details on environment you use, aka Specifications paragraph!
After providing all this info we will decide what to do with this issue.

P.S. Start using markdown code blocks with correct language to provide nice and easy to read configs in description.

@raman-m raman-m added invalid Not actually an issue question Initially seen a question could become a new feature or bug or closed ;) waiting Waiting for answer to question or feedback from issue raiser labels May 30, 2023
@raman-m
Copy link
Member

raman-m commented Jun 7, 2023

@Shonzon

Have you resolved your Docker issue or haven't?

@raman-m
Copy link
Member

raman-m commented Jun 15, 2023

Have you find some workaround for the issue?
Did you understand a root cause?

I believe your issue is related to Docker but not to Ocelot.
You need to show the root cause of Ocelot to accept the issue for fixing.

Let's find some workaround within one week please!
Your issue will be accepted or declined until June 23.

@abdulwahid211
Copy link

I'm still having the same issues running this in docker, what's the latest update?

@abdulwahid211
Copy link

abdulwahid211 commented Jun 15, 2023

Solved!

@Shonzon @raman-m

First step
Make sure you remove these methods from program.cs

app.UseHttpsRedirection();
app.UseAuthorization();

Second step
On your Ocelot json file, set all your routes localhost to your microservice names (docker-compose file) for example below

{
  "Routes": [
    {
      "DownstreamPathTemplate": "/api/Authenticate/{everything}",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "authenticationservice",
          "Port": 80
        }
      ],
      "UpstreamPathTemplate": "/api/Authenticate/{everything}",
      "UpstreamHttpMethod": [ "POST", "GET" ]
    }
  ]
}

@raman-m
Copy link
Member

raman-m commented Jun 15, 2023

@abdulwahid211 Hi Abdul!
You are right!
The downstream hosts are wrong in ocelot routes when using docker-compose project. They must be the same hosts as service names in docker-compose config.
I guess this is the root cause of the issue.

Also, I doubt docker-compose config.
We need not specify networks config section. It should be implicit.

It is always hard to find the root cause when the people copies and pastes logs, configs with bad formatting.
I ask people to upload the solution to GitHub to verify.

Anyway, thanks for your eagle eye! 🦅
You've found the root cause! ✌️

@raman-m
Copy link
Member

raman-m commented Jun 16, 2023

Hi @Shonzon !
Our Ocelot community has provided you the solution! It seems we've found the root cause for your user case.

I'm going to close the issue...
If you find in future that something wrong with Ocelot, you could reopen this or open a new issue.

Good luck in your endeavour with Ocelot!

@raman-m raman-m closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2023
@raman-m raman-m added wontfix No plan to include this issue in the Ocelot core functionality. and removed question Initially seen a question could become a new feature or bug or closed ;) waiting Waiting for answer to question or feedback from issue raiser labels Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Not actually an issue wontfix No plan to include this issue in the Ocelot core functionality.
Projects
None yet
Development

No branches or pull requests

3 participants