I have asp.net core project developed in my machine with docker support. The docker file resides in my project.
i.e, its placed outside the modules and under the rootfolder.
This image is working perfectly fine when I run using Visual studio.
#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
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["WebApplication4.csproj", ""]
RUN dotnet restore "./WebApplication4.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "WebApplication4.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication4.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication4.dll"]
I have created a pipeline in Azure Devops. and pushed the same code the way it is in my system, to azure git repository. but it fails to at workdir itself.
What is that I am missing here?
Related
1. MY Docker file is below.
#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/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["TestAPI/TestAPI.csproj", "TestAPI/"]
RUN dotnet restore "TestAPI/TestAPI.csproj"
COPY . .
WORKDIR "/src/TestAPI"
RUN dotnet build "TestAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "TestAPI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestAPI.dll"]
2. My solution structure is below.
Solution Structure
3.Folder structure
Folder structure
4.Error I am getting is below:
Docker build error
I have created web api in .net core 3.1 with docker file and include the DAL project. DAL project is common for all API. This is my project structure
--Solution
dockerfile
--DAL Project
This is my docker file format
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["Notification.csproj", ""]
COPY ["../DAL/DAL.csproj", "../DAL/"]
RUN dotnet restore "./Notification.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "Notification.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Notification.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Notification.dll"]
While build the application VS Code I got below error
COPY failed: failed to resolve scoped path ..\DAL_DAL.csproj (): evalSymlinksInScope: \?\C:\ProgramData\Docker\tmp\DAL\DAL.csproj is not in \?\C:\ProgramData\Docker\tmp\docker-builder572417841. Possible cause is a forbidden path outside the build context
Any help would be appreciated.
this is my project structure;
And this is my Dockerfile in SampleApp.API;
Maybe it can be an example for you.
I created a blazor project using .netcore3.1.
I use PhysicalFileProvider in startup.cs.
I ran it with docker using config in docker.
The build was successful, but an exception occurred during execution.
The docker file is as follows:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1903 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1903 AS build
WORKDIR /src
COPY ["Web/Web.csproj", "Web/"]
RUN dotnet restore "Web/Web.csproj"
COPY . .
WORKDIR "/src/Web"
RUN dotnet build "Web.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Web.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Web.dll"]
This is a docker file automatically generated by Visual Studio.
Why can't the program find the directory?
Or, is there another way to find the directory?
I would like to make REST calls to my ASP Core Web Api running in Docker by using Postman. Here is my Dockerfile:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1903 AS base
WORKDIR /app
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1903 AS build
WORKDIR /src
COPY ["MyApp.API/MyApp.API.csproj", "MyApp.API/"]
RUN dotnet restore "MyApp.API/MyApp.API.csproj"
COPY . .
WORKDIR "/src/MyApp.API"
RUN dotnet build "MyApp.API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyApp.API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyApp.API.dll"]
Using Visual Studio 2019, I click on the Docker run button which builds the image and creates a container. However, Postman cannot access the API running in Docker. The error message is "Error: connect ECONNREFUSED 127.0.0.1:51005." Is there a port command that I should use? If so, where should I put it? Thanks.
I am trying to build image for .net core 3.1 web api project but unable to build image
i get stuck at restoring project packages via dotnet restore
i get stuck at when i use dotnet build command ( does not find the solution or project file)
Directory Structure
https://i.stack.imgur.com/J7sMq.png
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as base
#FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1903 AS base
WORKDIR /app
#copy all project and solution files
COPY ./SSFS.Service/.csproj ./SSFS.Service/
COPY ./SSF.EDM/.csproj ./SSF.EDM/
COPY ./API/.csproj ./API/
COPY ./.sln ./
WORKDIR /app/API
RUN dotnet restore "SSFAPI.csproj"
#copy rest of files
COPY . .
WORKDIR /app
#build the project to restore packages
RUN dotnet build --source "./SSFAPI.sln" -c Release -o /publish
#public the project to a folder
RUN dotnet publish --source "SSFAPI.sln" -c Release -o /publish
FROM base AS final
EXPOSE 80
WORKDIR /app
COPY --from=base /app/publish .
ENTRYPOINT ["dotnet", "SSFAPI.dll"]
output of above is as below
https://i.stack.imgur.com/xqoKv.png
If i build the project using dotnet command then out is as shown below
Output is as below
https://i.stack.imgur.com/t9bV5.png
The Dockerfile is set up to be run from the solution root. You're probably running docker build from the project directory (i.e. where the Dockerfile actually is).