docker - 使用 ocelot 和 docker 服务使用路由 ApiGateway 时出错

标签 docker asp.net-core routes api-gateway ocelot

我正在使用 ocelot 创建一个 ApiGateway,它在 net core 中使用一个 Api 服务。 ApiGateway 和 ApiService 部署在 docker 上,docker compose 是这样的: Docker-compose:

tresfilos.webapigateway:
image: ${DOCKER_REGISTRY-}tresfilosapigateway
build: 
  context: .
  dockerfile: tresfilos.ApiGateway/ApiGw-Base/Dockerfile

tresfilos.users.service:
image: ${DOCKER_REGISTRY-}tresfilosusersservice
build: 
  context: .
  dockerfile: tresfilos.Users.Service/tresfilos.Users.Service/Dockerfile

Docker-compose.override:

tresfilos.webapigateway:
environment: 
  - ASPNETCORE_ENVIRONMENT=Development
  - IdentityUrl=http://identity-api
ports:
  - "7000:80"
  - "7001:443"
volumes:
  - ./tresfilos.ApiGateway/Web.Bff:/app/configuration

tresfilos.users.service:
environment: 
  - ASPNETCORE_ENVIRONMENT=Development
  - ASPNETCORE_URLS=https://+:443;http://+:80
ports:
  - "7002:80"
  - "7003:443"
volumes:
  - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
  - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro

configuration ocelot apigateway 中,我将 .json 定义为:

 "ReRoutes": [
 {
   "DownstreamPathTemplate": "/api/{version}/{everything}",
   "DownstreamScheme": "http",
   "DownstreamHostAndPorts": [
     {
       "Host": "tresfilos.users.service",
       "Port": 7002
     }
   ],
   "UpstreamPathTemplate": "/api/{version}/user/{everything}",
   "UpstreamHttpMethod": [ "POST", "PUT", "GET" ]
 },
],
"GlobalConfiguration": {
  "BaseUrl":  "https://localhost:7001"
 }

当我从 url 使用 ApiGateway 时: http://localhost:7000/api/v1/user/Login/authentication

我在终端 docker 中有错误: enter image description here

为什么会出现上述错误,如何解决?

最佳答案

您运行的是哪个版本的 Ocelot?

我发现另一个线程有类似的问题,显然从 Ocelot 的 16.0.0 版本开始,Ocelot 配置文件中的“ReRoutes”已更改为“Routes”。

我找到的主题是 - 404 trying to route the Upstream path to downstream path in Ocelot

关于docker - 使用 ocelot 和 docker 服务使用路由 ApiGateway 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65344815/

相关文章:

linux - Dockerfile 未执行第二阶段

java - JKS 文件是否独立于创建它的计算机?

.net - 将 .NET Core 应用程序部署为 Docker 化容器的好处?

asp.net-core - .net 核心在单一操作方法上覆盖 Controller 级别授权属性

javascript - 如何将 React Router location prop 传递给组件?

html - 在 Angular 6 中使用 HTML anchor 链接#id

amazon-web-services - AWS Elastic Beanstalk的Dockerfile错误;否则,有区别吗?

docker - Kitematic(Docker)中的 "Use VirtualBox instead of Native on next restart"是做什么的?

asynchronous - 如何检查是否在 Async C# MVC Core 方法中添加了实体项

ruby-on-rails - Ruby on Rails : How to link/route from one view/page to another view/page with a different controller