📝 Production Dockerfile = Güvenli Image
Production image’lar güvenli olmalı. Adım adım Dockerfile Best Practices ile production-ready image oluşturun.
🎯 Adım 1-5: Production Dockerfile
# Adım 1: Build Stage
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
# Adım 2: Dependency Restore
COPY *.csproj .
RUN dotnet restore
# Adım 3: Build
COPY . .
RUN dotnet publish -c Release -o /app
# Adım 4: Runtime Stage
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
WORKDIR /app
# Adım 5: Non-root User
RUN addgroup -g 1001 -S app && \
adduser -S app -u 1001
USER app
# Adım 6: Copy Build Artifacts
COPY --from=build /app .
# Adım 7: Environment Settings
ENV ASPNETCORE_ENVIRONMENT=Production
ENV DOTNET_RUNNING_IN_CONTAINER=true
# Adım 8: Security Settings
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s \
CMD curl -f http://localhost:8080/health || exit 1
# Adım 9: Entry Point
ENTRYPOINT ["dotnet", "MyApp.dll"]
🎯 Adım 10-12: Best Practices
# Adım 10: .dockerignore **/.classpath **/.dockerignore **/.env **/.git **/.gitignore **/.project **/.settings **/.toolstarget **/.vs **/.vscode **/*.*proj.user **/*.dbmdl **/*.jfm **/bin **/charts **/docker-compose* **/compose* **/Dockerfile* **/node_modules **/npm-debug.log **/obj **/secrets.dev.yaml **/values.dev.yaml README.md # Adım 11: Build Command docker build -t myapp:latest . docker build --no-cache -t myapp:latest . # Adım 12: Security Scan docker scan myapp:latest trivy image myapp:latest
✅ Best Practices Özet
- ✓ Multi-stage build
- ✓ Non-root user
- ✓ .dockerignore kullanımı
- ✓ Healthcheck ekleme
- ✓ Security scanning
Production Dockerfile best practices, container güvenliğini ve performansını artırır. Her geliştiricinin bilmesi gereken temel bilgilerdir.
