55SK55
55SK55

Reputation: 691

Docker File - Skipping Project. Because it was not found

I have a 3 Projects in a solution.

[Solution] 'BuySellApi' (3 Projects)
  | 
  +-- [BuySellApi]
  |    |
  |    +--- BuySellApi.csproj (This project holds the Docker file)
  |
  +-- [BuySellApi.Core]
  |    |
  |    +--- BuySellApi.Core.csproj
  |
  +-- [BuySellApi.Data]
       |
       +--- BuySellApi.Data.csproj

 1. BuySellApi.csproj -> API
 2. BuySellApi.Data/BuySellApi.Data.csproj -> Model
 3. BuySellApi.Core/BuySellApi.Core.csproj -> Data Access

I'm trying to build this using Docker by specifying following commands in Dockerfile

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5000

FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ["BuySellApi.csproj", "./"]
COPY ["BuySellApi.Data/BuySellApi.Data.csproj", "./"]
COPY ["BuySellApi.Core/BuySellApi.Core.csproj", "./"]
RUN dotnet restore "./BuySellApi.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "BuySellApi.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "BuySellApi.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "BuySellApi.dll", "--server.urls", "http://0.0.0.0:5000"]

After running the following command

docker build -t cog/buysellapi .

I'm getting the error as below:

e:\Apps\trunk\BuySell\BuySellApi>docker build -t cog/buysellapi .
Sending build context to Docker daemon  19.15MB
Step 1/19 : FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
 ---> ce06b36fcba4
Step 2/19 : WORKDIR /app
 ---> Using cache
 ---> 184385dc16fb
Step 3/19 : EXPOSE 5000
 ---> Using cache
 ---> 0e0cdd17e04d
Step 4/19 : ENV ASPNETCORE_URLS=http://+:5000
 ---> Using cache
 ---> 54cee58d679f
Step 5/19 : FROM microsoft/dotnet:2.2-sdk AS build
 ---> a4974ac66bfc
Step 6/19 : WORKDIR /src
 ---> Using cache
 ---> 7f9a2990f973
Step 7/19 : COPY ["BuySellApi.csproj", "./"]
 ---> Using cache
 ---> d526083ece6d
Step 8/19 : COPY ["BuySellApi.Data/BuySellApi.Data.csproj", "./"]
COPY failed: stat /mnt/sda1/var/lib/docker/tmp/docker-builder475321395/BuySellApi.Data/BuySellApi.Data.csproj: no such file or directory

It is not copying Data and Core Layers. When I try the same thing for a Solution with Single Project, It is working fine.

Upvotes: 20

Views: 23713

Answers (4)

Omid Ebrahimi
Omid Ebrahimi

Reputation: 1190

If someone needs a separate Dockerfile for each project, you can put each Dockerfile in the project folder and use docker-compose to build and run them separately. The trick here is to config your docker-compose.yaml like this:

# [Solution Folder]/docker-compose.yaml

services:
  app1:
    build:
      context: .
      dockerfile: ./Project1/Dockerfile
    ...
  app2:
    build:
      context: .
      dockerfile: ./Project2/Dockerfile
  ...

Note: Inside each Dockerfile, you should assume you are in the solution folder (not in the project folder). So for example you will have a line like this in your Project1/Dockerfile:

COPY ["Project1/Project1.csproj", "Project1/"]

Upvotes: 0

Mihai
Mihai

Reputation: 10767

Based on your input I propose below folder structure and Dockerfile.

[Solution] 'BuySellApi' (3 Projects)
  |
  +-- Dockerfile
  | 
  +-- [BuySellApi]
  |    |
  |    +--- BuySellApi.csproj
  |
  +-- [BuySellApi.Core]
  |    |
  |    +--- BuySellApi.Core.csproj
  |
  +-- [BuySellApi.Data]
       |
       +--- BuySellApi.Data.csproj

Dockerfile

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5000
    
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY . .
RUN dotnet restore ". BuySellApi/BuySellApi.csproj"
WORKDIR "/src/BuySellApi"
RUN dotnet build "BuySellApi.csproj" -c Release -o /app
    
FROM build AS publish
WORKDIR "/src/BuySellApi"
RUN dotnet publish "BuySellApi.csproj" -c Release -o /app
    
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "BuySellApi.dll", "--server.urls", "http://0.0.0.0:5000"]

Upvotes: 20

MiguelSlv
MiguelSlv

Reputation: 15193

In my case the project file was not found because i was building a linux container, and for some reason, the project filename and it's path had different letter case then in the filesystem.

Upvotes: 18

55SK55
55SK55

Reputation: 691

As suggested by @Mihai

I moved my Dockerfile directly under solution file and made some changes to it as below:

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5000

FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ["BuySellApi/BuySellApi.csproj", "BuySellApi/"]
COPY ["BuySellApi.Core/BuySellApi.Core.csproj", "BuySellApi.Core/"]
COPY ["BuySellApi.Data/BuySellApi.Data.csproj", "BuySellApi.Data/"]
RUN dotnet restore "BuySellApi/BuySellApi.csproj"
COPY . .
WORKDIR "/src/BuySellApi"
RUN dotnet build "BuySellApi.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "BuySellApi.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "BuySellApi.dll", "--server.urls", "http://0.0.0.0:5000"]

Upvotes: 4

Related Questions