Home > Software engineering >  Create an image containing .net core sdk and install custom templates inside the image
Create an image containing .net core sdk and install custom templates inside the image

Time:10-28

I am creating a docker image using visual studio console application and the dockerfile looke like:

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS base
RUN dotnet new --install MyCustomTemplate::1.0.0
WORKDIR /app
    
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["DockerTemplates/DockerTemplates.csproj", "DockerTemplates/"]
RUN dotnet restore "DockerTemplates/DockerTemplates.csproj"
COPY . .
WORKDIR "/src/DockerTemplates"
RUN dotnet build "DockerTemplates.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "DockerTemplates.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DockerTemplates.dll"]

After creating the image from sdk, I have called the command to install the custom template using the command:

RUN dotnet new --install MyCustomTemplate::1.0.0

But when the image is created, I don't find my custom template in my docker image.

How can I install custom templates inside a image during creation of the image? Anybody can help?

Thanks

CodePudding user response:

I try to replicate but can't.

Dockerfile

FROM mcr.microsoft.com/dotnet/sdk:5.0
RUN dotnet new --install Amazon.Lambda.Templates::5.5.0

Commands

docker build -t test .
docker run --rm test dotnet new --list

Lists the standard templates the new ones

  • Related