0

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

Satyajit
  • 1,971
  • 5
  • 28
  • 51
  • can you give some more info where you put the "RUN" command? Did you create a new Dockerfile or do you modifiy the existing one? Your command is executed in the defined WORKDIR. Did you choose the correct WORKDIR or do a `cd /my_install_dir && dotnet new ...`? – Michael Dreher Oct 27 '21 at 12:48
  • Crating a new dockerfile from mcr.microsoft.com/dotnet/sdk:5.0 and the dotnet templates get installed from nuget source – Satyajit Oct 27 '21 at 12:54
  • How do you see that the template isn't there? When I try to replicate your issue, the templates are installed in the image. I don't see the purpose for installing them, but they're there. – Hans Kilian Oct 27 '21 at 13:26
  • I can also see the standard templats but the new custom template is not installed. – Satyajit Oct 27 '21 at 13:27
  • How do you see that it's not installed? – Hans Kilian Oct 27 '21 at 13:30
  • In docker desktop, i can give command to check if its installed. dotnet new --list – Satyajit Oct 27 '21 at 13:32

1 Answers1

1

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

Hans Kilian
  • 18,948
  • 1
  • 26
  • 35