Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# - Stage 1 --------------------------------------------------------------------

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src

# Copy and restore dependencies
COPY src/Dotnet.Samples.AspNetCore.WebApi/*.csproj ./Dotnet.Samples.AspNetCore.WebApi/
RUN dotnet restore ./Dotnet.Samples.AspNetCore.WebApi

# Copy source and publish
COPY src/Dotnet.Samples.AspNetCore.WebApi ./Dotnet.Samples.AspNetCore.WebApi
WORKDIR /src/Dotnet.Samples.AspNetCore.WebApi
RUN dotnet publish -c Release -o /app/publish

# - Stage 2 --------------------------------------------------------------------

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
WORKDIR /app

# Copy published output
# Note: This includes the SQLite database because it's marked as <Content> with
# <CopyToOutputDirectory> in the .csproj file. No need to copy it manually.
COPY --from=build /app/publish .

# Add non-root user (aspnetcore) for security hardening
RUN adduser --disabled-password --gecos '' aspnetcore \
&& chown -R aspnetcore:aspnetcore /app
USER aspnetcore

# Set environment variables
ENV ASPNETCORE_URLS=http://+:9000
ENV ASPNETCORE_ENVIRONMENT=Production

# Default entrypoint
ENTRYPOINT ["dotnet", "Dotnet.Samples.AspNetCore.WebApi.dll"]
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,29 @@ _Figure: Simplified, conceptual project structure and main application flow. Not
dotnet watch run --project src/Dotnet.Samples.AspNetCore.WebApi/Dotnet.Samples.AspNetCore.WebApi.csproj
```

## Documentation
## Documentation (Development-only)

```console
https://localhost:9000/swagger/index.html
```

![API Documentation](/assets/images/Swagger.png)

## Container

This project includes a multi-stage `Dockerfile` for local development and production builds.

### Build the image

```bash
docker build -t aspnetcore-app .
```

### Run the container

```bash
docker run -p 9000:9000 aspnetcore-app

## Credits

The solution has been coded using [Visual Studio Code](https://code.visualstudio.com/) with the [C# Dev Kit](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit) extension.
Expand Down
Loading