I added a docker support to a dot.net core application, this is what I got
#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:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["SMSys.csproj", ""]
COPY ["../DataLayer/DataLayer.csproj", "../DataLayer/"]
COPY ["../Utilities/Utilities.csproj", "../Utilities/"]
COPY ["../ServiceLayer/ServiceLayer.csproj", "../ServiceLayer/"]
RUN dotnet restore "./SMSys.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "SMSys.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "SMSys.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SMSys.dll"]
My docker file is where 'SMSys.csproj' is.
If I run docker inside that directory, I get:
COPY failed: forbidden path outside the build context:
If I change some of the references of the project after the copy commands and run docker from the outside of the directory where all my projects are, I get multiple over a thousand of errors relating to my solution. The errors relate to missing things (assemblies and packages) as if all the projects are oblivious to one another when in fact they should be well referenced to one another as they do when I launch the project through visual studio.
This is an example of a solution that I followed that didnt work. https://www.jamestharpe.com/docker-include-files-outside-build-context/
Whats the best solution to implement in order to run my project through docker?
UPDATE
FROM mcr.microsoft.com/dotnet/aspnet:5.0.3-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0.103-buster-slim AS build
WORKDIR /src
# Prevent 'Warning: apt-key output should not be parsed (stdout is not a terminal)'
ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1
# install NodeJS 13.x
# see https://github.com/nodesource/distributions/blob/master/README.md#deb
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get install -y mc
#RUN apt-get install curl gnupg -yq
#RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install -y npm
COPY ["SMSysSolution/SMSys.csproj", "SMSysSolution/"]
COPY ["DataLayer/DataLayer.csproj", "DataLayer/"]
COPY ["Utilities/Utilities.csproj", "Utilities/"]
COPY ["ServiceLayer/ServiceLayer.csproj", "ServiceLayer/"]
COPY ["XUnitIntegrationTests/XUnitIntegrationTests.csproj", "XUnitIntegrationTests/"]
COPY ["XUnitTestProject1/XUnitTestProject1.csproj", "XUnitTestProject1/"]
RUN dotnet restore "./SMSysSolution/SMSys.csproj"
COPY . .
WORKDIR "/src/SMSysSolution"
RUN dotnet build "SMSys.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "SMSys.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SMSys.dll"]
I had to put a few changes to the paths to make it work.