Visual Studio 2022 and Docker Desktop

Hey Guys
I have problem with Visual Studio and Docker.
When I run my project in Visual Studio (with selected “Docker”) the images are properly created and the container is created. I can access the program via localhost:[port] (in web browser).
But when I stop my program in Visual Studio, access via localhost:[port] it doesn’t work (container with my program still run).
What I need to do to fix it (for the program to work in Docker despite the Visual Studio closed)? My dockerfile:

FROM AS base

FROM AS build
COPY ["WebApp/WebApp.csproj", "WebApp/"]
RUN dotnet restore "WebApp/WebApp.csproj"
COPY . .
WORKDIR "/src/WebApp"
RUN dotnet build "WebApp.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "WebApp.csproj" -c Release -o /app/publish

FROM base AS final
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApp.dll"]

Thanks a lot.

Unfortunately I don’t use Visual Studio, only Visual Studio Code. VSCode can forward local ports to remote services . Could this be what is happening to you with Visual Studio? If it doesn’t use Docker’s port forwarding or forwards random ports to containers and then forwards local ports to those random ports, that could explain why those local ports doesn’t workafter you close Visual Studio.

Try to run

docker ps -a

before and after you close Visual Studio code. Check if the ports forwards of the containers are correct.