aspnet / aspnet-docker

[Archived] ASP.NET Core Docker images for 1.x. Go to https://github.com/dotnet/dotnet-docker for 2.1 and up.
https://asp.net
719 stars 171 forks source link

Calling node js file inside docker windows container using INodeService giving error. #399

Closed arupbaroi closed 6 years ago

arupbaroi commented 6 years ago

After searching hours with the exception , I got to know this is an existing issue. But I am reporting this to get some work around for my use case. Because I need it badly.

I have a asp.net core api application running under a windows docker container. In my application I invoke node js using INodeService . It is working fine in local mode without docker and also working well in any cloud hosting without docker. But when I am running my application inside docker windows container, I am getting following exception in my InodeServices.InvokeAsync() method where I am giving the location of the js file and other parameters.

Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException: ENOENT: no such file or directory, lstat 'C:\ContainerMappedDirectories' Error: ENOENT: no such file or directory, lstat 'C:\ContainerMappedDirectories' at Object.patchedLStat [as lstat] (C:\Users\ContainerAdministrator\AppData\Local\Temp\32zx2v0u.50k:155:27) at Object.realpathSync (fs.js:1649:15) at toRealPath (module.js:158:13) at tryFile (module.js:154:22) at tryExtensions (module.js:166:22) at Function.Module._findPath (module.js:219:20) at Function.Module._resolveFilename (module.js:536:25) at Function.Module._load (module.js:468:25) at Module.require (module.js:587:17) at require (internal/module.js:11:18) at Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance.d71.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.d131.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.d101.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.d101.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at WebApplication1.Implementation.AssetReportMgr.d__10.MoveNext() in C:\sourceTree\connected assets\253\careports\HON.SPS.SIOT.CA.REPORT.API\HON.SPS.SIOT.CA.REPORT.API\Implementation\AssetReportMgr.cs:line 143

Here is my invoking code and docker file details:

var report = await _nodeServices.InvokeAsync<byte[]>("./pdf", html, data);

the pdf.js file is under my project root directory.

dockerFile:

FROM microsoft/aspnetcore:2.0-nanoserver-sac2016 AS base

ENV NODE_VERSION 8.9.4 ENV NODE_DOWNLOAD_SHA 48946e99ac4484e071df25741d2300f3a656f476c5ff3f8116a4746c07ebe3b7

Retrieve node and git https://nodejs.org/dist/v8.9.4/ ENV NODE_VERSION 8.9.4 ENV NODE_DOWNLOAD_SHA 48946e99ac4484e071df25741d2300f3a656f476c5ff3f8116a4746c07ebe3b7

RUN Invoke-WebRequest -UseBasicParsing https://nodejs.org/dist/v${env:NODE_VERSION}/node-v${env:NODE_VERSION}-win-x64.zip -outfile node.zip; if ((Get-FileHash node.zip -Algorithm sha256).Hash -ne $env:NODE_DOWNLOAD_SHA) { Write-Host 'NODEJS CHECKSUM VERIFICATION FAILED!'; exit 1; };

Expand-Archive node.zip -DestinationPath nodejs-tmp; Move-Item nodejs-tmp/node-v${env:NODE_VERSION}-win-x64 "${Env:ProgramFiles}/nodejs"; Remove-Item -Force node.zip; Remove-Item -Force nodejs-tmp

RUN setx /M PATH $($Env:PATH + ';' + $Env:ProgramFiles + '/nodejs')

WORKDIR /app EXPOSE 80

FROM microsoft/aspnetcore-build:2.0-nanoserver-sac2016 AS build WORKDIR /src COPY *.sln ./ COPY HON.SPS.SIOT.CA.REPORT.API/HON.SPS.SIOT.CA.REPORT.API.csproj HON.SPS.SIOT.CA.REPORT.API/ COPY HON.SPS.SIOT.CA.REPORT.Azure.Blob/HON.SPS.SIOT.CA.REPORT.Azure.Blob.csproj HON.SPS.SIOT.CA.REPORT.Azure.Blob/ RUN dotnet restore COPY . . WORKDIR /src/HON.SPS.SIOT.CA.REPORT.API RUN dotnet build -c Release -o /app

FROM build AS publish RUN dotnet publish -c Release -o /app

FROM base AS final WORKDIR /app COPY --from=publish /app . RUN npm install ENTRYPOINT ["dotnet", "HON.SPS.SIOT.CA.REPORT.API.dll"]

Dockercompose File:

version: '3'

services: hon.sps.siot.ca.report.api: image: hon.sps.siot.ca.report.api build: context: . dockerfile: HON.SPS.SIOT.CA.REPORT.API\Dockerfile

Node Version: 8.9.4 Platform: Docker Windows Container

If will be great help if some one tell me how to provide the relative path for pdf.js because /pdf is not working here.

natemcmaster commented 6 years ago

Sorry for the slow response on this issue. Were you able to find an answer to your question? From what I can tell, this doesn't look a problem in the ASP.NET Core image itself, but rather how your app is configured to run inside Docker. It appears to me you're missing a directory which you're expecting to be mapped to a Docker volume, but I didn't see this volume configuration in the docker-compose file or mentioned elsewhere.

By the way, if not, you might try asking the same question on StackOverflow where there is a much bigger audience to help you.

natemcmaster commented 6 years ago

Closing due to lack of response. Feel free to continue discussion. We can re-open if you can provide more information about problems that we need to make changes to fix.