Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ocelot和docker服务使用路由网关时出错_Docker_Asp.net Core_Routes_Api Gateway_Ocelot - Fatal编程技术网

使用ocelot和docker服务使用路由网关时出错

使用ocelot和docker服务使用路由网关时出错,docker,asp.net-core,routes,api-gateway,ocelot,Docker,Asp.net Core,Routes,Api Gateway,Ocelot,我正在使用ocelot创建一个Api网关,它使用NetCore中的Api服务。 ApiGateway和ApiService部署在docker上,docker由以下方式组成: Docker compose: tresfilos.webapigateway: image: ${DOCKER_REGISTRY-}tresfilosapigateway build: context: . dockerfile: tresfilos.ApiGateway/ApiGw-Base/Dockerfil

我正在使用ocelot创建一个Api网关,它使用NetCore中的Api服务。 ApiGateway和ApiService部署在docker上,docker由以下方式组成: 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
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
Docker compose.override

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
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
配置中我定义了.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

我在terminal docker中有错误:


为什么会出现上述错误以及如何修复它?

您正在运行哪个版本的Ocelot

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

我找到的线程是-

我用以下方法修复它:

  • 将重路由更改为路由,因为ocelot版本为16.0.1

  • 定义配置,如:

    “路线”:[ { “DownstreamPathTemplate”:“/api/{version}/{everything}”, “下游模式”:“http”, “下游港口”:[ { “主机”:“tresfilos.users.service”, “端口”:7002 } ], “UpstreamPathTemplate”:“/api/{version}/User/{everything}” }, ], “全球配置”:{ “BaseUrl”:https://localhost:7001" }

  • 在postman中,我以类似json的形式发送数据,而不是像paramaters那样发送数据


  • (谢谢JasonS).

    16.0.1版,当更改为Routes时会生成错误更改为Routes后会出现什么错误?System.AggregateException:'发生一个或多个错误。(无法启动Ocelot,错误为:身份验证选项AuthenticationProviderKey:IdentityApiKey,AllowedScopes:[]是不受支持的身份验证提供程序)'