Search code examples
.netdockerdocker-compose.net-8.0

Docker failed file can not be found


I am having an issue building my docker image. Please find my file below:

#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["BookWooks.OrderApi/Directory.Packages.props", "BookWooks.OrderApi/"]
COPY ["BookWooks.OrderApi/Directory.Build.props", "BookWooks.OrderApi/"]
COPY ["BookWooks.OrderApi/nuget.config", "BookWooks.OrderApi/"]
COPY ["BookWooks.OrderApi/src/BookWooks.OrderApi.Web/BookWooks.OrderApi.Web.csproj", "BookWooks.OrderApi/src/BookWooks.OrderApi.Web/"]
COPY ["BookWooks.OrderApi/src/BookWooks.OrderApi.Infrastructure/BookWooks.OrderApi.Infrastructure.csproj", "BookWooks.OrderApi/src/BookWooks.OrderApi.Infrastructure/"]
COPY ["BookyWooks.SharedKernel/BookyWooks.SharedKernel.csproj", "BookyWooks.SharedKernel/"]
COPY ["BookWooks.OrderApi/src/BookWooks.OrderApi.Core/BookWooks.OrderApi.Core.csproj", "BookWooks.OrderApi/src/BookWooks.OrderApi.Core/"]
COPY ["BookyWooks.Messaging/BookyWooks.Messaging.csproj", "BookyWooks.Messaging/"]
COPY ["BookWooks.OrderApi/src/BookWooks.OrderApi.UseCases/BookWooks.OrderApi.UseCases.csproj", "BookWooks.OrderApi/src/BookWooks.OrderApi.UseCases/"]
RUN dotnet restore "./BookWooks.OrderApi/src/BookWooks.OrderApi.Web/BookWooks.OrderApi.Web.csproj"
COPY . .
WORKDIR "/src/BookWooks.OrderApi/src/BookWooks.OrderApi.Web"
RUN dotnet build "./BookWooks.OrderApi.Web.csproj" -c $BUILD_CONFIGURATION -o /app/build

# Integration Test Stage
FROM build as integrationtest
WORKDIR "/src/BookyWooks.OrderApi.IntegrationTests"

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./BookWooks.OrderApi.Web.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "BookWooks.OrderApi.Web.dll"]

I get the following error:

Step 8/29 : COPY ["BookWooks.OrderApi/Directory.Packages.props", "BookWooks.OrderApi/"]
COPY failed: file not found in build context or excluded by .dockerignore: stat BookWooks.OrderApi/Directory.Packages.props: file does not exist

Here is my project structure: enter image description here enter image description here enter image description here

This file does exist and it is in the correct location. I believe I only got this issue after upgrading from .net 7 to .net 8. Would anyone know what is causing this?


Solution

  • I am using: docker build . I am doing this from the folder where the dockerfile is located

    The Dockerfile (at least the one I was able to find on the screenshots) is located inside the BookWooks.OrderApi/src/BookWooks.OrderApi.Web so if you are building it from that folder then docker build context clearly does not have all the folders/files specified in the COPY commands, so from the point of the docker build context the "This file does exist and it is in the correct location." claim is incorrect.

    Either move the docker file to the root of the solution (BookyWooksOnlineStore) and run it from there or run the command from this folder (BookyWooksOnlineStore) and specify path to the docker file, something along the following:

    docker build -f BookWooks.OrderApi/src/BookWooks.OrderApi.Web/Dockerfile .