Base solution for your next web application
Open Closed

Deploy ASPNET ZERO to Digital Ocean using docker file. #12125


User avatar
0
mmorales created

I am trying to deploy ASPNETZERO to Digital Ocean but I am getting an error. Here is the docker file on the host folder: #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:7.0 AS base WORKDIR /app EXPOSE 80 EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build WORKDIR /src COPY ["src/WebPortal.Web.Host/WebPortal.Web.Host.csproj", "src/WebPortal.Web.Host/"] COPY ["src/WebPortal.Web.Core/WebPortal.Web.Core.csproj", "src/WebPortal.Web.Core/"] COPY ["src/WebPortal.Application/WebPortal.Application.csproj", "src/WebPortal.Application/"] COPY ["src/WebPortal.Application.Shared/WebPortal.Application.Shared.csproj", "src/WebPortal.Application.Shared/"] COPY ["src/WebPortal.Core.Shared/WebPortal.Core.Shared.csproj", "src/WebPortal.Core.Shared/"] COPY ["src/WebPortal.Core/WebPortal.Core.csproj", "src/WebPortal.Core/"] COPY ["src/WebPortal.EntityFrameworkCore/WebPortal.EntityFrameworkCore.csproj", "src/WebPortal.EntityFrameworkCore/"] COPY ["src/WebPortal.GraphQL/WebPortal.GraphQL.csproj", "src/WebPortal.GraphQL/"] RUN dotnet restore "src/WebPortal.Web.Host/WebPortal.Web.Host.csproj" COPY . . WORKDIR "/src/src/WebPortal.Web.Host" RUN dotnet build "WebPortal.Web.Host.csproj" -c Release -o /app/build

FROM build AS publish RUN dotnet publish "WebPortal.Web.Host.csproj" -c Release -o /app/publish

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

Below is the deployment file

[2024-08-20 16:54:33] ╭──────────── git repo clone ───────────╼ [2024-08-20 16:54:33] │ › fetching app source code [2024-08-20 16:54:33] │ => Selecting branch "master" [2024-08-20 16:54:36] │ => Checking out commit "4d33feaad8f449c47655b2a179cd75d79dc7b3ef" [2024-08-20 16:54:37] │ [2024-08-20 16:54:37] │ ✔ cloned repo to /.app_platform_workspace [2024-08-20 16:54:37] ╰────────────────────────────────────────╼ [2024-08-20 16:54:37] [2024-08-20 16:54:37] › applying source directory /src/WebPortal.Web.Host [2024-08-20 16:54:37] ✔ using workspace root /.app_platform_workspace/src/WebPortal.Web.Host [2024-08-20 16:54:37] [2024-08-20 16:54:37] ╭──────────── dockerfile build ───────────╼ [2024-08-20 16:54:37] │ › using dockerfile /.app_platform_workspace/Dockerfile [2024-08-20 16:54:37] │ › using build context /.app_platform_workspace//src/WebPortal.Web.Host [2024-08-20 16:54:37] │ [2024-08-20 16:54:37] │ INFO[0000] Resolved base name mcr.microsoft.com/dotnet/aspnet:7.0 to base [2024-08-20 16:54:37] │ INFO[0000] Resolved base name mcr.microsoft.com/dotnet/sdk:7.0 to build [2024-08-20 16:54:37] │ INFO[0000] Resolved base name build to publish
[2024-08-20 16:54:37] │ INFO[0000] Resolved base name base to final
[2024-08-20 16:54:37] │ INFO[0000] Retrieving image manifest mcr.microsoft.com/dotnet/aspnet:7.0 [2024-08-20 16:54:37] │ INFO[0000] Retrieving image mcr.microsoft.com/dotnet/aspnet:7.0 from registry mcr.microsoft.com [2024-08-20 16:55:07] │ INFO[0030] Retrieving image manifest mcr.microsoft.com/dotnet/aspnet:7.0 [2024-08-20 16:55:07] │ INFO[0030] Returning cached image manifest
[2024-08-20 16:55:07] │ INFO[0030] Retrieving image manifest mcr.microsoft.com/dotnet/sdk:7.0 [2024-08-20 16:55:07] │ INFO[0030] Retrieving image mcr.microsoft.com/dotnet/sdk:7.0 from registry mcr.microsoft.com [2024-08-20 16:55:37] │ INFO[0060] Retrieving image manifest mcr.microsoft.com/dotnet/sdk:7.0 [2024-08-20 16:55:37] │ INFO[0060] Returning cached image manifest
[2024-08-20 16:55:37] │ INFO[0060] Built cross stage deps: map[2:[/app/publish]] [2024-08-20 16:55:37] │ INFO[0060] Retrieving image manifest mcr.microsoft.com/dotnet/aspnet:7.0 [2024-08-20 16:55:37] │ INFO[0060] Returning cached image manifest
[2024-08-20 16:55:37] │ INFO[0060] Retrieving image manifest mcr.microsoft.com/dotnet/aspnet:7.0 [2024-08-20 16:55:37] │ INFO[0060] Returning cached image manifest
[2024-08-20 16:55:37] │ INFO[0060] Executing 0 build triggers
[2024-08-20 16:55:37] │ INFO[0060] Building stage 'mcr.microsoft.com/dotnet/aspnet:7.0' [idx: '0', base-idx: '-1'] [2024-08-20 16:55:37] │ INFO[0060] Cmd: EXPOSE
[2024-08-20 16:55:37] │ INFO[0060] Adding exposed port: 80/tcp
[2024-08-20 16:55:37] │ INFO[0060] Cmd: EXPOSE
[2024-08-20 16:55:37] │ INFO[0060] Adding exposed port: 443/tcp
[2024-08-20 16:55:37] │ INFO[0060] Skipping unpacking as no commands require it. [2024-08-20 16:55:37] │ INFO[0060] Initializing snapshotter ...
[2024-08-20 16:55:37] │ INFO[0060] Taking snapshot of full filesystem...
[2024-08-20 16:55:37] │ INFO[0060] WORKDIR /app
[2024-08-20 16:55:37] │ INFO[0060] Cmd: workdir
[2024-08-20 16:55:37] │ INFO[0060] Changed working directory to /app
[2024-08-20 16:55:37] │ INFO[0060] Creating directory /app with uid -1 and gid -1 [2024-08-20 16:55:37] │ INFO[0060] Taking snapshot of files...
[2024-08-20 16:55:37] │ INFO[0060] EXPOSE 80
[2024-08-20 16:55:37] │ INFO[0060] Cmd: EXPOSE
[2024-08-20 16:55:37] │ INFO[0060] Adding exposed port: 80/tcp
[2024-08-20 16:55:37] │ INFO[0060] No files changed in this command, skipping snapshotting. [2024-08-20 16:55:37] │ INFO[0060] EXPOSE 443
[2024-08-20 16:55:37] │ INFO[0060] Cmd: EXPOSE
[2024-08-20 16:55:37] │ INFO[0060] Adding exposed port: 443/tcp
[2024-08-20 16:55:37] │ INFO[0060] No files changed in this command, skipping snapshotting. [2024-08-20 16:55:37] │ INFO[0060] Storing source image from stage 0 at path /kaniko/stages/0 [2024-08-20 16:55:38] │ INFO[0061] Deleting filesystem...
[2024-08-20 16:55:38] │ INFO[0061] Retrieving image manifest mcr.microsoft.com/dotnet/sdk:7.0 [2024-08-20 16:55:38] │ INFO[0061] Returning cached image manifest
[2024-08-20 16:55:38] │ INFO[0061] Retrieving image manifest mcr.microsoft.com/dotnet/sdk:7.0 [2024-08-20 16:55:38] │ INFO[0061] Returning cached image manifest
[2024-08-20 16:55:38] │ INFO[0061] Executing 0 build triggers
[2024-08-20 16:55:38] │ INFO[0061] Building stage 'mcr.microsoft.com/dotnet/sdk:7.0' [idx: '1', base-idx: '-1'] [2024-08-20 16:55:38] │ error building image: error building stage: failed to optimize instructions: failed to get files used from context: failed to get fileinfo for /.app_platform_workspace/src/WebPortal.Web.Host/src/WebPortal.Web.Host/WebPortal.Web.Host.csproj: lstat /.app_platform_workspace/src/WebPortal.Web.Host/src/WebPortal.Web.Host/WebPortal.Web.Host.csproj: no such file or directory [2024-08-20 16:55:38] │ [2024-08-20 16:55:38] │ command exited with code 1 [2024-08-20 16:55:38] │ [2024-08-20 16:55:38] │ ✘ build failed


1 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi mmorales

    1- Ensure that the paths in the COPY commands match the actual structure of your repository. For instance, if the WebPortal.Web.Host.csproj file is actually located in /src/WebPortal.Web.Host/ relative to your repository root, your Dockerfile's COPY command should correctly reflect this.

    2- If the .csproj files are in the correct locations, try adjusting the COPY paths in your Dockerfile as follows:

    • Removed the src/ directory from the COPY statements:
    • Adjusted WORKDIR paths: Changed the WORKDIR from /src/src/WebPortal.Web.Host to /src/WebPortal.Web.Host to align with the correct directory structure during the Docker build.
    FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
    WORKDIR /app
    EXPOSE 80
    EXPOSE 443
    
    FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
    WORKDIR /src
    COPY ["WebPortal.Web.Host/WebPortal.Web.Host.csproj", "WebPortal.Web.Host/"]
    COPY ["WebPortal.Web.Core/WebPortal.Web.Core.csproj", "WebPortal.Web.Core/"]
    COPY ["WebPortal.Application/WebPortal.Application.csproj", "WebPortal.Application/"]
    COPY ["WebPortal.Application.Shared/WebPortal.Application.Shared.csproj", "WebPortal.Application.Shared/"]
    COPY ["WebPortal.Core.Shared/WebPortal.Core.Shared.csproj", "WebPortal.Core.Shared/"]
    COPY ["WebPortal.Core/WebPortal.Core.csproj", "WebPortal.Core/"]
    COPY ["WebPortal.EntityFrameworkCore/WebPortal.EntityFrameworkCore.csproj", "WebPortal.EntityFrameworkCore/"]
    COPY ["WebPortal.GraphQL/WebPortal.GraphQL.csproj", "WebPortal.GraphQL/"]
    RUN dotnet restore "WebPortal.Web.Host/WebPortal.Web.Host.csproj"
    COPY . .
    WORKDIR "/src/WebPortal.Web.Host"
    RUN dotnet build "WebPortal.Web.Host.csproj" -c Release -o /app/build
    
    FROM build AS publish
    RUN dotnet publish "WebPortal.Web.Host.csproj" -c Release -o /app/publish
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app/publish .
    ENTRYPOINT ["dotnet", "WebPortal.Web.Host.dll"]