You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Blazor/Documentation/docusaurus/docs/deploy/generate-docker-file.md

58 lines
1.4 KiB

---
sidebar_position: 1
sidebar_label: Generate Docker file
title: Generate Docker file
---
## How to generate my docker file
It is possible to generate a `Dockerfile` automaticly with Visual Studio.
On your project, click right and select `Add` => `Docker Support...`:
![Docker Support](/img/deploy/docker-support-visual-studio.png)
Select the `Linux` target:
![Target OS](/img/deploy/docker-file-options.png)
A new file `Dockerfile` are created in your project.
## The nuget configuration
If you use specific repositories, you must use a `nuget.config` file.
Don't forget to add your `nuget.config` to your build image, just after `WORKDIR /src` add `COPY ["nuget.config", "."]`
:::caution
If you don't add the file, restore nuget does not work, by default restore search on nuget.org
:::
## Example of Dockerfile
```txt
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["nuget.config", "."]
COPY ["MyBeautifulApp/MyBeautifulApp.csproj", "MyBeautifulApp/"]
RUN dotnet restore "MyBeautifulApp/MyBeautifulApp.csproj"
COPY . .
WORKDIR "/src/MyBeautifulApp"
RUN dotnet build "MyBeautifulApp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyBeautifulApp.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyBeautifulApp.dll"]
```