'Github Action Docker Image of ASP.net Core application
So I'm trying to build a docker image of an asp.net project that I created in Visual Studio with Docker enabled.
Now my understanding is that the .dockerignore file is in the solutions folder and the Dockerfile is in the project file, so I have to run my script from within the solution folder, and then tell it that the docker file is located at /Restraunts_API/Dockerfile for it to run correctly. (yes I know its spelt wrong)
I can't see why this isn't working
name: Docker Image CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./EcoBadge_Solution/
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build --tag apirestaurant:$(date +%s) --file Restraunt_API/Dockerfile .
It is set to run in my solution folder and the Dockerfile is set as the one in the project folder. Why cant it find my .csproj file?
The github action errors with
Step 7/17 : COPY ["Restraunt_API/Restraunt_API.csproj", "Restraunt_API/"]
COPY failed: file not found in build context or excluded by .dockerignore: stat Restraunt_API/Restraunt_API.csproj: file does not exist
Error: Process completed with exit code 1.
And the Dockerfile looks like
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Restraunt_API/Restraunt_API.csproj", "Restraunt_API/"]
RUN dotnet restore "Restraunt_API/Restraunt_API.csproj"
COPY . .
WORKDIR "/src/Restraunt_API"
RUN dotnet build "Restraunt_API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Restraunt_API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Restraunt_API.dll"]
Solution 1:[1]
The cause of the problem was that the Dockerfile was not in the correct location.
Please move the Dockerfile to the upper folder path, it will solve this problem. It means move the dockfile from the project directory to the solution directory.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jason |
