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"]
Related
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?
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.
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"]
Getting an error in the Azure DevOps Pipeline:
Step 7/17 : COPY ["demo6/demo6.csproj", "demo6/"]
COPY failed: file not found in build context or excluded by .dockerignore: stat demo6/demo6.csproj: file does not exist
NOTES-run the pipeline in diagnostics mode and the .sln file exists
##[debug]cwd=/home/vsts/work/1/s
##[debug] /home/vsts/work/1/s/demo6.sln (file)
##[debug] /home/vsts/work/1/s/demo6/demo6.csproj (file)
I have a multi-project Asp.Net Core solution with the folder structure and projects as follows:
demo6
|--demo6/demo6.csproj
|--demo6.api/demo6.api.csproj
The app is demo6 which references demo6.api which is a class library.
This is in GitHub in a repository demo6. I modified the autogenerated Dockerfile to add the extra demo6/ to see if that works but no.
Appreciate any help.
Dockerfile below:
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["demo6/demo6.csproj", "demo6/"]
RUN dotnet restore "demo6/demo6.csproj"
COPY . .
WORKDIR "/src/demo6"
RUN dotnet build "demo6.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "demo6.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "demo6.dll"]
Also tried this:
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["demo6/demo6/demo6.csproj", "ddemo6/"]
RUN dotnet restore "ddemo6/demo6.csproj"
COPY . .
WORKDIR "/src/ddemo6"
RUN dotnet build "demo6.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "demo6.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "demo6.dll"]
Got this error:
Step 7/17 : COPY ["demo6/demo6/demo6.csproj", "ddemo6/"]
COPY failed: file not found in build context or excluded by .dockerignore: stat demo6/demo6/demo6.csproj: file does not exist
##[error]COPY failed: file not found in build context or excluded by .dockerignore: stat demo6/demo6/demo6.csproj: file does not exist
here's the repo structure
The reason of file not found error may be the relative path of the Dockerfile and the csproj are different. Try to set the Dockerfile in the root of the solution should solve your error.
Also you need to add a buildContext with the csproj folder.
buildContext: Path to the build context
Also, here is a case you can refer to.
One more possible cause of COPY failed: no source files were specified is .dockerignore file present in your workspace
Look for .dockerignore file because of docker’s CLI (command line interface) it sends context to the docker daemon to load the .dockerignore file.
If the .dockerignore file exist in the context than it might be possible there is exclude entry to ignore the build directory
# ignore or exclude build directory
*/build*
*/*/build*
I have a simple ASP.NET Core solution that I dockerize and seems that some files that are supposedly copied to the output as always are not present when my application is running via Docker.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-bionic AS base
ENV RUNNING_IN_DOCKER=true
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-bionic AS source
WORKDIR /src
COPY ["SecretProject.Core/SecretProject.Core.csproj", "SecretProject.Core/"]
COPY ["SecretProject.DAL/SecretProject.DAL.csproj", "SecretProject.DAL/"]
COPY ["SecretProject.Utils/SecretProject.Utils.csproj", "SecretProject.Utils/"]
COPY ["SecretProject.Externals/SecretProject.Externals.csproj", "SecretProject.Externals/"]
COPY ["NuGet.Config", "/"]
RUN dotnet restore "SecretProject.Core/SecretProject.Core.csproj"
FROM source AS build
COPY . .
WORKDIR "/src/SecretProject.Core"
RUN dotnet build "SecretProject.Core.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "SecretProject.Core.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SecretProject.Core.dll"]
Missing files are the ones there: SecretProject.Core/Views/EmailTemplates/*.*
I would like to see the files when the container is running, I am indeed suspecting that not everything is copied.
Instead of having all these lines
COPY ["SecretProject.Core/SecretProject.Core.csproj", "SecretProject.Core/"]
COPY ["SecretProject.DAL/SecretProject.DAL.csproj", "SecretProject.DAL/"]
COPY ["SecretProject.Utils/SecretProject.Utils.csproj", "SecretProject.Utils/"]
COPY ["SecretProject.Externals/SecretProject.Externals.csproj", "SecretProject.Externals/"]
COPY ["NuGet.Config", "/"]
Replace for
COPY . .