# Deploy an ASP.NET Core .NET 10 API with Docker

Gregale · Updated 2026-12-01

Build a minimal ASP.NET Core API for Linux, bind Kestrel to the host port, deploy to Gregale, and verify the exact release response.

**Deploy an ASP.NET Core .NET 10 API to Gregale with a Linux Dockerfile.**
Use Microsoft's SDK image to build and its ASP.NET runtime image to run. Set
Kestrel to listen on `0.0.0.0` and the port Gregale passes in `PORT`. A Dockerfile
is the path for this example; it does not depend on a native .NET builder.

[View the source on GitHub](https://github.com/gregale-dev/aspnet-core-docker)
or [download the complete .NET 10 example](https://gregale.dev/examples/aspnet-core-docker.zip).
It starts a minimal API without a database, credentials, or external packages.
`GET /ready` returns a marker from inside the application, and
`GET /greet/world` returns `{"message":"Hello, world!"}`.

## Match the container's port to the host

Inside the container, localhost is private to the process. Kestrel must listen
on all interfaces so Gregale can route requests to it. Microsoft's ASP.NET
container images default to port 8080, but making the application read
`PORT` avoids a mismatch when the host sets a different port.

```csharp
var port = Environment.GetEnvironmentVariable("PORT") ?? "8080";
if (!int.TryParse(port, out var listenPort) || listenPort is < 1 or > 65535)
{
    throw new InvalidOperationException("PORT must be a TCP port between 1 and 65535.");
}
builder.WebHost.UseUrls($"http://0.0.0.0:{listenPort}");
```

The Dockerfile declares `EXPOSE 8080` and starts `dotnet GreetingApi.dll` as the
image's non-root user. `EXPOSE` documents the port; it does not tell Kestrel to
bind. Gregale terminates HTTPS before requests reach the container. The
server listens over HTTP internally, so the sample does not redirect its
internal readiness request to HTTPS.

## Run it locally

Unzip the sample, change into the extracted directory, and run:

```bash
docker build --platform linux/amd64 -t aspnet-greeting .
docker run --rm -p 8080:8080 -e PORT=8080 aspnet-greeting
```

In a second terminal:

```bash
curl -fsS http://localhost:8080/ready
curl -fsS http://localhost:8080/greet/world
```

The example's `gregale.yaml` sets `hosting.health: /ready`, an endpoint served by
this application rather than a platform liveness URL.

## Deploy and verify on Gregale

Install the [Gregale CLI](https://gregale.dev/docs/install.md), then authenticate and deploy from
the extracted directory. Pick a fresh name rather than reusing a production app.

```bash
gregale login
gregale deploy --path . --name aspnet-greeting
```

A successful deploy prints the app URL. If the app allows public requests,
send a GET to its URL and check the JSON. For a private app, use the deployment
UUID reported by `gregale --json deploy` or shown on the release page:

```bash
gregale release verify DEPLOYMENT_UUID --app aspnet-greeting --path /ready
gregale release verify DEPLOYMENT_UUID --app aspnet-greeting --path /greet/world
```

A passing readiness check doesn't prove your business endpoint works. Check
that the second call returns the expected greeting. Owner-authorized release
verification checks the specified revision; it does not prove anonymous
access or which version serves public traffic.

## What passed on Gregale

On December 1, 2026, we deployed the exact sample from a Dockerfile to a
disposable app on a Scale account. Owner-authorized GETs returned HTTP 200
with the expected readiness marker and `{"message":"Hello, world!"}`. We
then staged a second build using `gregale deploy --no-traffic`. Its exact
release returned `{"message":"Preview hello, world!"}` while the first
release retained 100% of routing and its original response. The second
release had 0%. This tests a staged release; it is not a GitHub PR preview
or a fresh Free-account verification.

## If the deploy builds but never becomes ready

| Symptom                                         | Check                                                                                         |
| ----------------------------------------------- | --------------------------------------------------------------------------------------------- |
| Readiness times out                             | Confirm Kestrel binds to `0.0.0.0:$PORT`, not `localhost`.                                    |
| `/ready` is 404                                 | Confirm it is mapped in `Program.cs` and the deployed image includes that source.             |
| Wrong architecture                              | Build for `linux/amd64`, especially on Apple Silicon.                                         |
| App runs but the public request is unauthorized | Verify the app's access policy; keep the API private unless it is intended for anonymous use. |

When you are done, remove only the test app you created. Do not reuse these
commands against an existing service without reviewing the target.

Sources: [Microsoft: .NET container port defaults](https://learn.microsoft.com/en-us/dotnet/core/compatibility/containers/8.0/aspnet-port),
[Gregale container compatibility](https://gregale.dev/docs/container-compatibility.md), and
[Gregale: deployment verification](https://gregale.dev/docs/quickstart.md).

## Questions

### Can you deploy an ASP.NET Core .NET 10 API to Gregale?

Yes, deploy a Linux Dockerfile with the .NET runtime in the image. This guide uses the container path, not a native .NET builder.

### What port should ASP.NET Core listen on in Docker?

Bind Kestrel to 0.0.0.0 and read the PORT environment variable from the host. This sample falls back to 8080 when PORT is unset.

### How do you verify a private deployment without making it public?

Use gregale release verify with the exact deployment UUID and your application path. It runs an authenticated GET and does not verify public access.

Canonical URL: https://gregale.dev/articles/deploy-aspnet-core-docker

