Problem: A web service application works fine in IIS Server but does not work if hosted in a docker image in Docker desktop.
Analysis: The web service application was using an external software. The dependent software files were not getting copied to the docker image. Hence the web application was failing to do the operation.
Solution: The solution was to update the docker file that was generated by Visual Studio while docker support is added. The following changes were made to the docker file to copy the dependent software to the docker image. The files to be copied from the host system also has to be present relative to the docker file. In this case the Model folder is at the same level of the docker file.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build
WORKDIR /src
COPY ["YourProject.csproj", ""]
RUN dotnet restore "./YourProject.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "YourProject.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "YourProject.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
COPY <Dependent software files> /app/<directory in docker image>
COPY <Model> /app/<Model>
ENTRYPOINT ["dotnet", "YourProject.dll"]
Apart from the changes in docker file, some changes are required in the source file (.cs) for referring the files copied in the container. Relative path to the app folder was used instead of using System.IO API's. For example, one of the following changes was made in my case:
var projectPath = "xxx";
var workingdir = @"Model"; // The path of the files were accessed based on the app process working directory
Comments
Post a Comment