Skip to content

Commit

Permalink
Update docker samples to the recommended format
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat committed Jan 21, 2025
1 parent f1fbe5c commit e0556c1
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions content/documentation/hosting/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ running your app is as easy as:

```bash
# creates an image named "myproject"
docker build -f Dockerfile.linux-x64 -t myproject .
docker build -f Dockerfile -t myproject .

# runs your application
docker run -p 8080:8080 -d myproject
Expand All @@ -36,37 +36,36 @@ you will not need to install the .NET SDK or any other dependencies besides Dock
## Creating a new Dockerfile

If you did not use a project template, create a new file named `Dockerfile` in the
root directory of your repository. The following example is for an x64 image
running on Linux:
root directory of your repository and paste the following content:

```dockerfile
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
ARG TARGETARCH
WORKDIR /source

# copy csproj and restore as distinct layers
COPY Project/*.csproj .
RUN dotnet restore -r linux-musl-x64
COPY --link Project/*.csproj .
RUN dotnet restore -a "$TARGETARCH"

# copy and publish app and libraries
COPY Project/ .
RUN dotnet publish -c release -o /app -r linux-musl-x64 --no-restore /p:PublishTrimmed=true /p:TrimMode=Link
COPY --link Project/. .
RUN dotnet publish --no-restore -a "$TARGETARCH" -o /app

# final stage/image
FROM mcr.microsoft.com/dotnet/runtime-deps:9.0-alpine-amd64
WORKDIR /app
COPY --from=build /app .

ENTRYPOINT ["./Project"]
# Enable globalization and time zones:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md

FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine
EXPOSE 8080
WORKDIR /app
COPY --link --from=build /app .
USER $APP_UID
ENTRYPOINT ["./Project"]
```

This assumes that you named your project `Project`. With this file you can use
the commands in the previous section to build and run your project.

## Managing dependencies

Typically your web application will have some dependencies such as databases
Typically, your web application will have some dependencies such as databases
or a redis server. [docker compose](https://docs.docker.com/compose/gettingstarted/)
allows you to define and maintain the whole infrastructure needed by your app
in a single file.

0 comments on commit e0556c1

Please sign in to comment.