0

I am new to Docker. I have installed DockerDesktop. I am trying to expose an ASP.NET Core Web API via docker containers.

This is my docker file:

# This stage is used to build the service project
FROM *****/dotnet-80-sdk-runtime:latest AS builder #local artificatory within my company
ARG BUILD_CONFIGURATION=Release
WORKDIR /build
USER root
COPY ./NuGet.Config ./NuGet.Config 
COPY . .
RUN ls -la
RUN dotnet restore "./GrafProm.API.csproj" --configfile ./NuGet.Config
RUN dotnet build "./GrafProm.API.csproj" -c Release --no-restore -o /app/buildOutput
RUN dotnet publish "./GrafProm.API.csproj" -c Release --no-restore -o /app/publish

FROM *****/dotnet-80-runtime:latest AS run
EXPOSE 8080
ENV ASPNETCORE_URLS=http://+:8080
ENV DOTNET_ROOT=/usr/mware/dotnet
ENV ASPNETCORE_ENVIRONMENT=development
USER root
RUN mkdir -p /var/log/containers
#
WORKDIR /app
COPY --from=builder /app/publish .
ENTRYPOINT ["dotnet", "GrafProm.API.dll"]

I am using VS 2022 and this is my launchsettings.json file:

 "profiles": {
    "http": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "dotnetRunMessages": true,
      "applicationUrl": "http://localhost:5293"
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Container (Dockerfile)": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
      "environmentVariables": {
        "ASPNETCORE_HTTP_PORTS": "8080"
      },
      "publishAllPorts": true,
      "useSSL": false
    }

When I run the container (Dockerfile) in VS, the image and container are getting created, but I get this error:

enter image description here

Instead of getting swagger page, I am getting an error page in IE.

Can someone help?

Thanks in advance.

6
  • Hi user1447718,may I know if the project copy from other machine or download from some where ? If yes, please try to remove and re-add the docker support, then try again. Commented Nov 13, 2024 at 6:17
  • 1
    @JasonPan no , i didnt download the project from anywhere... i created it manually in my localbox. thanks. Commented Nov 13, 2024 at 6:27
  • How about using other sdk runtime? Instead of FROM *****/dotnet-80-sdk-runtime:latest AS builder #local artificatory within my company. I mean we can test it to verify the issue is related to image or not. Commented Nov 13, 2024 at 6:56
  • when i build it from command promot using below commands docker build -t grafprom.api.img . docker run --rm -p8081:8080 grafprom.api.img:latest, it worked when i entered the url localhost:8081/swagger/index.html in browser. which is expected. but when i run it from visual studio docker shortcut, that's when am facing this issue... Commented Nov 13, 2024 at 16:23
  • Hi user1447718, I understand your previous attempts to use the command line to work well with your company's own image. However, I still insist that you use Microsoft's official image for testing to see if you encounter the same error. Commented Nov 14, 2024 at 6:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.