1.6 KiB
1.6 KiB
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
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
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