While working on a ServiceFabric based solution and building a docker image I am getting the following because of my directory structure :
My directory structure is
D:
D1:
src:
Foo.Fabric:
Foo.Fabric: -----------------> This is context right now
.vs
Foo.Service:
DockerFile
Foo.Service.csproj
docker-compose.yml
.dockerignore
Foo.Lib:
Foo.Lib:
Foo.Lib.csproj
The content of my docker-compose.yml is like :
version: '3.4'
services:
foo:
image: foodockerimage
build:
context: .
dockerfile: Foo.Service/Dockerfile
And the content of my dockerfile is as follows
FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY Foo.Service/Foo.Service.csproj Foo.Service/
COPY ../Foo.Lib/Foo.Lib/Foo.Lib.csproj ../Foo.Lib/Foo.Lib/
RUN dotnet restore Foo.Service/Foo.Service.csproj
COPY . .
WORKDIR /src/Foo.Service
RUN dotnet build Foo.Service.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish Foo.Service.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Foo.Service.dll"]
As we can see here clearly that I need to build this Lib.csproj along with my main Foo.Service.csproj The problem is the directory location of Lib project. Becuase this is used by some other solutions, I can not not move this Lib project inside the Foo.Fabric folder.
Now initially I got the error of "Service 'foo' failed to build: COPY failed: Forbidden path outside the build context: ../Foo.Lib/Foo.Lib/Foo.Lib.csproj", OK I got this, I have a wrong context so I updated in docker-compose.yml as
build: context: . to build: context: ..
to change the context to the parent directory of the current directory, so again I will have to change the paths of dockerfile resulting a docker-compose.yml as
version: '3.4'
services:
foo:
image: foodockerimage
build:
context: ..
dockerfile: Foo.Fabric/Foo.Service/Dockerfile
And also
FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY Foo.Fabric/Foo.Service/Foo.Service.csproj Foo.Fabric/Foo.Service/ #Updated
COPY Foo.Lib/Foo.Lib/Foo.Lib.csproj Foo.Lib/Foo.Lib/ #Updated
RUN dotnet restore Foo.Service/Foo.Service.csproj
COPY . .
WORKDIR /src/Foo.Service
RUN dotnet build Foo.Service.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish Foo.Service.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Foo.Service.dll"]
Now I have this error "PermissionError: [Errno 13] Permission denied: '\\?\D:\D1\src\Foo.Fabric\.vs\Foo.Fabric\v15\Server\sqlite3\db.lock'"
I am really banging my haed with this and couldn't get up. By the way I am using :
Docker Desktop Community Version 2.0.0.0-win81(29211) Engine: 18.09.0
Visual Studio Professional 2017 15.9.3
Windows 10 1809
Make sure to exclude the .vs folder from your build, by using a '.dockerignore' file next to the dockerfile. Usually they look like this, for VS projects:
.dockerignore
.env
.git
.gitignore
.vs
.vscode
docker-compose.yml
docker-compose.*.yml
*/bin
*/obj