Exception on .setting file Save() function on docker Linux: ClientConfigurationHost::OpenStreamForWrite - c#

im working on a net7.0 ASP.NET Core Wen API project with linux docker build.
In my application i need to save some settings on a .setting file. Thats working well when i run my application on IIS Express on Windows.
Here is a simpel code example:
ApplicationSettings.Default.Test = "Test"
ApplicationSettings.Default.Save();
When i running this code on Docker build:
I get this exception on the .Save() functon:
"Failed to save settings: An error occurred loading a configuration file: An unexpected error occurred in 'ClientConfigurationHost::OpenStreamForWrite '' '''."
This docker file was created by visual studio.
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["ShippApiCollection/ShippApiCollection.csproj", "ShippApiCollection/"]
RUN dotnet restore "ShippApiCollection/ShippApiCollection.csproj"
COPY . .
WORKDIR "/src/ShippApiCollection"
RUN dotnet build "ShippApiCollection.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "ShippApiCollection.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ShippApiCollection.dll"]
Anybody had the same issue and can help me here?

Related

Unable to build Docker image for Arm32v7 with external assembly

I have an aspnet application which is using an external Assembly (from another project of mine).
I have added this as a project reference, and I can build and run my application locally fine, with no errors or problems.
But when trying to build this for Docker with Arm32v7 (Raspberry Pi) I get the error:
warning MSB3245: Could not resolve this reference. Could not locate
the assembly "SAM Shared". Check to make sure the assembly exists on
disk. If this reference is required by your code, you may get
compilation errors.
My docker file
#Below is changed to use the appropiate image for Rpi, arm32v7
FROM mcr.microsoft.com/dotnet/aspnet:6.0.1-bullseye-slim-arm32v7 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["HomeMonitor/HomeMonitor.csproj", "HomeMonitor/"]
COPY ["HomeMonitor.Shared/HomeMonitor.Shared.csproj", "HomeMonitor.Shared/"]
RUN dotnet restore "HomeMonitor/HomeMonitor.csproj"
COPY . .
WORKDIR "/src/HomeMonitor"
RUN dotnet build "HomeMonitor.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "HomeMonitor.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "HomeMonitor.dll"]

mcr.microsoft.com/dotnet/aspnet:6.0-jammy-chiseled: not found

I have created the default WeatherForecast web api project with Docker support.
By default, the dockerfile is using aspnet: 6.0
But I would like to upgrade it to 6.0-jammy-chiseled. This is my dockerfile after I have updated it to 6.0-jammy-chiseled
FROM mcr.microsoft.com/dotnet/aspnet:6.0-jammy-chiseled AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0-jammy-chiseled AS build
WORKDIR /src
COPY ["Weather2.csproj", "."]
RUN dotnet restore "./Weather2.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "Weather2.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Weather2.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Weather2.dll"]
When I run it, I got an error:
mcr.microsoft.com/dotnet/aspnet:6.0-jammy-chiseled: not found
I try to pull the image manually with docker pull mcr.microsoft.com/dotnet/nightly/aspnet:6.0-jammy-chiseled and it pull without issue.
Based on the Docker file of the official sample app, I think that your Docker file should be revised as
FROM mcr.microsoft.com/dotnet/nightly/aspnet:6.0-jammy-chiseled AS base (add nightly in the image path)
and
FROM mcr.microsoft.com/dotnet/sdk:6.0-jammy AS build (remove -chiseled as SDK has no need to be chiseled and Microsoft will not publish chiseled SDK but only chiseled runtime.

docker ASP.net web API 6.0 build - the type or namespace name could not be found

Im trying to make an ASP.NET API (.NET 6.0) that runs in docker.
I made the project with build in docker support from visual studio and set it to linux.
Also I included an custom assembly with functions i want to use abroad multiple applications.
Whenever I build the project in debug mode it works fine and starts up my project.
The build command:
docker build -f "C:\Users\USER\source\repos\PROJECT\PROJECT\Dockerfile" --force-rm -t PROJECT:dev --target base --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=PROJECT" "C:\Users\USER\source\repos\PROJECT"
But whenever i start it in release mode it gets rid of the "--target base" flag in the docker build command and gives me the error "The type or namespace name could not be found" of that assembly i try to include.
Also when i try a simple:
docker build -t /Dockerfile .
Gives me the same error.
My Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal AS base
WORKDIR /app
EXPOSE 443
ENV ASPNETCORE_URLS=http://+:443
FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS build
WORKDIR /src
COPY Project* .
RUN dotnet restore "Project.csproj"
COPY . .
RUN dotnet build "Project.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Project.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Project.dll"]

Docker Copy failed with ASP.net Core

I am trying to run my ASP.net Core application with docker, but for some reasons each time I try with different approach with the Dockerfile I fail by copying the directory.
What am I doing wrong? I tried the step by step guide in Microsoft web using my own proj but with unsuccess.
The cmd error I recieve:
C:\dev\Dmail\Dmail.API>docker build -t aspnetapp .
Sending build context to Docker daemon 21.79MB
Step 1/18 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
---> 47da1e9634dc
Step 2/18 : WORKDIR /app
---> Using cache
---> bf490aa67962
Step 3/18 : EXPOSE 80
---> Using cache
---> d172deff350a
Step 4/18 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
---> 4a651b73be3d
Step 5/18 : WORKDIR /src
---> Using cache
---> c607b7f04e23
Step 6/18 : COPY ["Dmail.API/Dmail.API.csproj", "Dmail.API/"]
COPY failed: stat /var/lib/docker/tmp/docker-builder531905822/Dmail.API/Dmail.API.csproj: no such file or directory
C:\dev\Dmail\Dmail.API>
Here is my DockerFile:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Dmail.API/Dmail.API.csproj", "Dmail.API/"]
COPY ["Dmail.Core/Dmail.Core.csproj", "Dmail.Core/"]
COPY ["Dmail.Data/Dmail.Data.csproj", "Dmail.Data/"]
RUN dotnet restore "Dmail.API/Dmail.API.csproj"
COPY . .
WORKDIR "/src/Dmail.API"
RUN dotnet build "Dmail.API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Dmail.API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Dmail.API.dll"]
So after long time of searching the web for a solution I managed to solve my problem.
First of all the Dockerfile was generated automatically by Visual Studio by pressing add onto the ASP.net project and then Docker Support.
The Visual Studio locate the file inside the project. What I did in order to solve the problem was to move the file as it is to the solution folder which is for me Dmail. For example my files were like this:
Dmail(solution)
Dmail.API(proj)
Dmail.Core(proj)
Dmail.Data(proj)

Asp.netcore app in docker debian

I have problem to run my container in docker, my docker is host on a server linux debian
this is my docker file
FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 5000
FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY *.sln ./
COPY DockerWebPage/DockerWebPage.csproj DockerWebPage/
RUN dotnet restore
COPY . .
WORKDIR /src/DockerWebPage
RUN dotnet build -c Release -o /app
FROM build AS publish
RUN dotnet publish -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "DockerWebPage.dll"]
and this is my console output:
root#vps564358:~# docker build -t dockerwebpage:dev /home/Container
Sending build context to Docker daemon 352MB
Step 1/18 : too much code for send all console build
b1dd0b04c119: Pull complete
91ea08ab0cc9: Pull complete
7f2893df5d93: Pull complete
6ca202fa6c2e: Pull complete
31b4abd59648: Pull complete
Digest: sha256:1e4043c2484157e029d6b09a3149ebd01c5122f6b62f0a1b6c6f54b90500ea4b
Status: Downloaded newer image for microsoft/aspnetcore-build:2.0
---> e4e43a027c0b
Step 6/18 : WORKDIR /src
---> bf0be7525f14
Removing intermediate container 9ff4196e50dc
Step 7/18 : COPY *.sln ./
No source files were specified
root#vps564358:~# docker run -d -p 5000:5000 dockerwebpage:dev
9fe41e5b2237364e141ed575c02afc02755b8a751ba65e57a395a8b633b5d022
so i think after that my web app could work, but when i try to connect to my site i have a error :"Connetion denied from "

Categories