I am a beginner in Docker, and I have a problem When I am trying to run Image Docker with a C# Project.
In my Asp.net net8 project, there is a basic Dockerfile such as this:
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["MyApiProject/MyApiProject.csproj", "MyApiProject/"]
RUN dotnet restore "./MyApiProject/MyApiProject.csproj"
COPY . .
WORKDIR "/src/MyApiProject"
RUN dotnet build "./MyApiProject.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./MyApiProject.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyApiProject.dll"]
When I am running the project from the Run button (by Visual studio), It’s working fine. The image is created, The container is running, and I can see it in the Browser with swagger on the specific container ports.
But, When I run it from PowerShell, It’s wrong. The container is running, But the result of the URL with swagger is:
This page is not working
localhost did not send data.
ERR_EMPTY_RESPONSE.
The status of cantainer is runnig, but log is empty.
I am trying some things, But I can’t resolve this problem.
I used one Docker Image with 2 containers, and ran it from PowerShell cmd.
I copy the Docker run command from output window of Visual Studio and run it by Powershell:
docker run -dt -v “C:…vsdbgvs2017u5:/remote_debugger:rw” -v
“C:…AppDataRoamingMicrosoftUserSecrets:/root/.microsoft/usersecrets:ro”
-v “C:…AppDataRoamingMicrosoftUserSecrets:/home/app/.microsoft/usersecrets:ro”
-v “C:…AppDataRoamingASP.NETHttps:/root/.aspnet/https:ro” -v “C:…AppDataRoamingASP.NETHttps:/home/app/.aspnet/https:ro” -v
“C:Program FilesMicrosoft Visual
Studio2022CommunityMSBuildSdksMicrosoft.Docker.Sdktoolslinux-x64net8.0:/VSTools:ro”
-v “C:Program FilesMicrosoft Visual Studio2022CommunityCommon7IDECommonExtensionsMicrosoftHotReload:/HotReloadAgent:ro”
-e “ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true” -e “ASPNETCORE_ENVIRONMENT=Development” -P –name MyApiProject_1
–entrypoint dotnet myapiproject –roll-forward Major /VSTools/DistrolessHelper/DistrolessHelper.dll –wait
But still is existing some problem.
Why can’t I run .net Docker application from PowerShell?
Maybe, If I will understand the behavior of the RUN button in Visual Studio, I can solve it?
Thank’s
ne0m is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.