简体   繁体   中英

How do you correctly set a .net core 3.1 web api url for docker-compose?

I am trying to set up and test an aspnetcore 3.1 web API using docker Linux containers. the container builds and runs the web API but the URL is as follows:

https://localhost:6001/https://%7BServiceHost%7D:6001/Swagger

It should be https://localhost:6001/Swagger

How should I have set up my docker file/docker-compose.yml to give the correct URL?

Docker file:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
EXPOSE 443

COPY . ./
RUN dotnet publish ApiProject -c Release -o out

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .

ENTRYPOINT ["dotnet", "ApiProject.dll", "--environment=Development"]

docker-compose.yml:

version: '3.4'

services:
  apiproject:
    image: ${DOCKER_REGISTRY-}apiproject
    environment:
      - ASPNETCORE_URLS=https://+:443;http://+:80
      - ASPNETCORE_HTTPS_PORT=443
    ports:
      - "6000:80"
      - "6001:443"
    build:
      context: .
      dockerfile: ApiProject/Dockerfile

docker-compose.override.yml:

version: '3.4'

services:
  checkoutpaymentgateway:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=https://+:443;http://+:80
      - ASPNETCORE_Kestrel__Certificates__Default__Password=helmet
      - ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
    volumes:
      - ~/.aspnet/https:/https:ro
    ports:
      - "6000:80"
      - "6001:443"

I faced the same problem. The solution for me was to recreate docker-compose file, as I saw later, the problem was in docker-compose.dcproj file. It's auto-generated by VS file. Try to open this file, which is located in the parent directory of your project with any text editor and checktag. In my situaton it was : {Scheme}://localhost:{ServicePort}/{Scheme}://{ServiceHost}:{ServicePort}/swagger. I removed {Scheme}://localhost:{ServicePort}/{Scheme} ://{ServiceHost}:{ServicePort} /swagger . To decide this problem you can chech this tag, or just regenerate docker-compose in VS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM