diff --git a/docs/task-08-create-dockerfile.md b/docs/task-08-create-dockerfile.md new file mode 100644 index 0000000..ef62f94 --- /dev/null +++ b/docs/task-08-create-dockerfile.md @@ -0,0 +1,74 @@ +# Task 8: Create Dockerfile + +## Task Description + +**Files:** +- Create: `src/Fengling.AuthService/Dockerfile` +- Create: `src/Fengling.AuthService/.dockerignore` + +## Implementation Steps + +### Step 1: Create Dockerfile + +Create: `src/Fengling.AuthService/Dockerfile` + +```dockerfile +FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base +WORKDIR /app +EXPOSE 80 + +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build +WORKDIR /src +COPY ["Fengling.AuthService.csproj", "./"] +RUN dotnet restore "Fengling.AuthService.csproj" +COPY . . +WORKDIR "/src" +RUN dotnet build "Fengling.AuthService.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "Fengling.AuthService.csproj" -c Release -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Fengling.AuthService.dll"] +``` + +### Step 2: Create .dockerignore + +Create: `src/Fengling.AuthService/.dockerignore` + +``` +bin/ +obj/ +Dockerfile +.dockerignore +*.md +``` + +### Step 3: Commit + +```bash +git add src/Fengling.AuthService/Dockerfile src/Fengling.AuthService/.dockerignore +git commit -m "feat(auth): add Dockerfile for containerization" +``` + +## Context + +This task adds Docker support for containerization. The multi-stage Dockerfile builds the project in a SDK container and copies only the runtime to a lightweight runtime container. + +**Tech Stack**: Docker, .NET 10.0 + +## Verification + +- [ ] Dockerfile created with multi-stage build +- [ ] .dockerignore created +- [ ] Dockerfile uses .NET 10.0 +- [ ] Exposes port 80 +- [ ] Committed to git + +## Notes + +- Multi-stage build reduces image size +- Only runtime container in final image +- Ready for Kubernetes deployment diff --git a/src/Fengling.AuthService/.dockerignore b/src/Fengling.AuthService/.dockerignore new file mode 100644 index 0000000..72acb0b --- /dev/null +++ b/src/Fengling.AuthService/.dockerignore @@ -0,0 +1,5 @@ +bin/ +obj/ +Dockerfile +.dockerignore +*.md diff --git a/src/Fengling.AuthService/Dockerfile b/src/Fengling.AuthService/Dockerfile new file mode 100644 index 0000000..736232d --- /dev/null +++ b/src/Fengling.AuthService/Dockerfile @@ -0,0 +1,19 @@ +FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base +WORKDIR /app +EXPOSE 80 + +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build +WORKDIR /src +COPY ["Fengling.AuthService.csproj", "./"] +RUN dotnet restore "Fengling.AuthService.csproj" +COPY . . +WORKDIR "/src" +RUN dotnet build "Fengling.AuthService.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "Fengling.AuthService.csproj" -c Release -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Fengling.AuthService.dll"]