Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
672 views
in Technique[技术] by (71.8m points)

docker - Starting container process caused: exec: "powershell": executable file not found in $PATH: unknown

I'm trying to containerize my .net core 3.1 service into linux Docker container. This service works with a SQL Server database, so I have a docker-compose as follows:

version: "3.5"

services:
    back:
        build: 
            context: ../../
            dockerfile: local_deploy/back/docker
        container_name: api
        restart: always
        environment:
          - ASPNETCORE_ENVIRONMENT=Development
        depends_on:
          - db-server
        ports:
          - "7000:80"
        networks:
          - localdev

    db-server:
        image: microsoft/mssql-server-linux:2017-latest
        container_name: db-server
        environment:
          - ACCEPT_EULA=Y
          - MSSQL_SA_PASSWORD=1234
          - MSSQL_TCP_PORT=1433
        ports:
          - "1400:1433"
        networks:
          - localdev

networks:
  localdev:
    name: localdev

To run this docker-compose I have a up.bat file into local_deploy/back directory inside the root folder of the solution:

@echo off

echo Starting build
rd ....out /s /Q
dotnet restore ../../MySimpleService.sln -s http://nexus.tools.example.com/nuget-v2/ -s https://nexus.eas.example.com/repository/nuget-hosted/
dotnet publish ../../MySimpleService.sln -c Release --force -o ../../out - /property:Version=1.0.0 /p:ASPNETCORE_ENVIRONMENT=Development

echo Starting containers
docker-compose up --build -d

And, finally, here is a docker file:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
COPY out ./
ENTRYPOINT ["dotnet", "MySimpleService.dll"]

All these three files are into local_deploy/back directory.

When I run up command in cmd, container is successfully built.

The problem is that the service also uses NATS as a message broker so it is down inside of a container because it can't establish connection with NATS.

To install and use NATS on my local machine I have to install a msi file prepared by our team. After installing this msi on my machine, I can run MySimpleService successfully locally.

So, my guess, to run this service into container I should also install this msi into container. I tried to edit my docker file:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

COPY out ./

RUN (New-Object System.Net.WebClient).DownloadFile('https://nexus.eas.example.com/repository/mars-nats-streaming-business/NatsStreaming_2.1.4-alpha386.msi', 'c:oolsNatsStreaming_2.1.4-alpha386.msi') ;
    Start-Process 'msiexec' -ArgumentList '/i c:oolsNatsStreaming_2.1.4-alpha386.msi /quiet /qn /norestart /log c:oolsinstallNatsStreaming.log'; 
    Start-Sleep -s 30 ;
    Remove-Item c:ools*.msi -force

ENTRYPOINT ["dotnet", "MySimpleService.dll"]

But I get an error:

Service 'back' failed to build : OCI runtime create failed:
container_linux.go:370: starting container process caused: exec:
"powershell": executable file not found in $PATH: unknown

Now my guess is that I should install a powershell into container.

Any help would be highly appreciated.

question from:https://stackoverflow.com/questions/65852056/starting-container-process-caused-exec-powershell-executable-file-not-found

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would say that your guess (Now my guess is that I should install a powershell into container.) is correct, yes :)

I had a similar problem and opted to replace the PowerShell command by a shell command, which ensures compatibility.

However, if you cannot replace your PowerShell command by a suitable shell, then, you may use the PowerShell in Docker, following the documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...