Can anyone please help me to create a docker file for blazor webassembly ?
I am trying to creating docker file for blazor webassembly.
I have checked many docs and I have tried with many docker files. Every time my docker image build successful but when I run that image at that time I am getting error like below
"It was not possible to find any installed .NET Core SDKs
Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from: https://aka.ms/dotnet-download"
I am using below code
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "BlazorDemo.dll"]
This is my build command and it's working fine
docker build --tag blazordemo .
Below run command I have tried and here I am getting error
docker run --publish 8001:80 --detach --name blazortestapp blazordemo
docker run -p 8080:80 blazordemo
Note - Blazor WebAssembly target framework is .NET Standard 2.1
Related
I'm trying to dockerize my .net core rest api app.
I refer to MS Menual which give docker sample and commands guidance and It worked well.
So, to try [dockerizing] myself, I created .Net Core Rest API app and checked 'Use Docker Support'.
I built image with 'Dockerfile' had been given by MS.
Below is Dockerfile
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["dockersupport.csproj", ""]
RUN dotnet restore "./dockersupport.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "dockersupport.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "dockersupport.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "dockersupport.dll"]
And I build it with
>$ docker build -t docksupport .
And run with
>$ docker run --rm -it -p 5000:80 --name dockersupport dockersupport
And server was running well. However I can't access to API swagger page.
When I tried to build/run with visual studio only, It showed swagger page well.
I tried to access to web page with url : 'localhost:5000/swagger/index.html' docker and local both.
I can't understand why MS sample app works well but my app doesn't. I wonder what is the differece between their and mine.
Would you share your knowledge or how can I access web page of my app?
In my code, swagger UI would be shown if environment is Development. However, I just set my docker environment Production.
I refer to this post Swagger UI gives 404 when app is running in Docker container
and I deleted if condition, It works well
I have looked at other posts related to this and couldn't resolve the issue.
Docker File:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY webapp/*.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY ./webapp ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT [ "dotnet", "weppapp.dll" ]
Local version of .NET Core:
PS C:\Repository\AzureCLIScripts\AZ203\ContainerizedSolutions> dotnet --version
3.1.201
I'm following along a training course on Docker, primarily related to the AZ-203 course, so I'm sure the original code is for .NET Core 2.1. I've researched as best I can, but can't seem to get the app to run inside of docker, when it runs fine locally.
When I run the following I get the error below:
PS C:\Repository\AzureCLIScripts\AZ203\ContainerizedSolutions> docker run -p 8081:80 --name mywebapp webapp
It was not possible to find any installed .NET Core SDKs
Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
https://aka.ms/dotnet-download
Any suggestions?
This happened to me when I changed the assembly name in the project but forgot to change it in the Dockerfile. Assembly name is in the project properties.
Following this link I build a .Net Core application and was able to run the application in a docker container. My host machine OS is Windows 10, and I now want to try to run the linked application in a Linux container. I have switched to Linux containers with Docker Desktop.
When I'm building the docker image I get this error:
failed to register layer: error creating overlay mount to /var/lib/docker/overlay2/f3e5279484774002c78a8eb66702c9ee7bca7038b59f4eeca7085b88dcbe25d9/merged: too many levels of symbolic links
The Dockerfile I've Used:
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-nanoserver-1903 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1903 AS build
WORKDIR /src
COPY ["NetCore.Docker/NetCore.Docker.csproj", "NetCore.Docker/"]
RUN dotnet restore "NetCore.Docker/NetCore.Docker.csproj"
COPY . .
WORKDIR "/src/NetCore.Docker"
RUN dotnet build "NetCore.Docker.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "NetCore.Docker.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "NetCore.Docker.dll"]
Thanks
reason for this is I was using wrong image, had to change the image which support linux containers
i created 2 default projects ( WEB API ) from visual studio , one with .net core 2.1 and the other with .net core 3.1! generated dockerfiles for both using visual studio !
dockerfile for both is like bellow
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build
your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:2.1 AS base // version 3.1 for my other project
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build // version 3.1 for my other project
WORKDIR /src
COPY ["WebApplication2.csproj", ""]
RUN dotnet restore "./WebApplication2.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "WebApplication2.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication2.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication2.dll"]
and this is my launchSetting
"applicationUrl": "http://localhost:80"
these are the exact command i use to build and run my dockerfile
docker build -t mohammadjavani/app21 .
docker run -p 8080:80 mohammadjavani/app21
docker build -t mohammadjavani/app31 .
docker run -p 8080:80 mohammadjavani/app31
after i run my app21 i could view my app in my brower in localhost:80
but as mohammadjavani/app31 after i stopped app21 container and run app31 i couldnt view my app in brower !
dockerfiles are generated in visual studio and commands i used are the exact same for both project
what could be wrong with my .net core 3.1 dockerfile project ??
Can you please try using the environment variable ASPNETCORE_URLS="https://+:443;http://+:80"
docker run -p 8080:80 mohammadjavani/app31 -e ASPNETCORE_URLS="https://+:443;http://+:80"
I want to run multiple instances of .net core API on windows server 2016 using windows docker container. I am able to create image and container successfully, but on invoking docker start the container are not running Up instead it exited with code (2147516566).
Here is my docker file content which is in published API directory
FROM mcr.microsoft.com/dotnet/core/runtime:2.2-nanoserver-sac2016
COPY / app/
ENTRYPOINT ["dotnet", "app/MyAPI.dll"]
I didn't spend long on it, but I didn't have good luck running binaries I built myself. The docker add in for visual studio always performs the build inside a container. I have adapted to this. Here is an example Dockerfile I have anonymized. Hopefully I didn't break anything:
# Base image for running final product
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-sac2016 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
# build asp.net application
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-sac2016 AS build
WORKDIR /src
COPY ["Test.Docker.Windows/Test.Docker.Windows.csproj", "Test.Docker.Windows/"]
RUN dotnet restore "Test.Docker.Windows/Test.Docker.Windows.csproj"
COPY . .
WORKDIR "/src/Test.Docker.Windows"
RUN dotnet build "Test.Docker.Windows.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "Test.Docker.Windows.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
# startup.bat contains dotnet test.Docker.Windows.dll
CMD ./startup.bat