[英]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.我正在尝试将我的 .net 核心 3.1 服务容器化到 linux Docker 容器中。 This service works with a SQL Server database, so I have a
docker-compose
as follows:该服务适用于 SQL 服务器数据库,所以我有一个
docker-compose
如下:
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:要运行此
docker-compose
,我在解决方案的根文件夹内的local_deploy/back
目录中有一个up.bat
文件:
@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:最后,这是一个
docker
文件:
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.所有这三个文件都在
local_deploy/back
目录中。
When I run up
command in cmd
, container is successfully built.当我在
cmd
中运行命令up
,容器已成功构建。
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.问题是该服务还使用 NATS 作为消息代理,因此它位于容器内部,因为它无法与 NATS 建立连接。
To install and use NATS on my local machine I have to install a msi file prepared by our team.要在我的本地机器上安装和使用 NATS,我必须安装我们团队准备的 msi 文件。 After installing this msi on my machine, I can run
MySimpleService
successfully locally.在我的机器上安装这个 msi 后,我可以在本地成功运行
MySimpleService
。
So, my guess, to run this service into container I should also install this msi into container.所以,我猜,要将这个服务运行到容器中,我还应该将这个 msi 安装到容器中。 I tried to edit my
docker
file:我试图编辑我的
docker
文件:
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:\tools\NatsStreaming_2.1.4-alpha386.msi') ;\
Start-Process 'msiexec' -ArgumentList '/i c:\tools\NatsStreaming_2.1.4-alpha386.msi /quiet /qn /norestart /log c:\tools\installNatsStreaming.log'; \
Start-Sleep -s 30 ;\
Remove-Item c:\tools\*.msi -force
ENTRYPOINT ["dotnet", "MySimpleService.dll"]
But I get an error:但我收到一个错误:
Service 'back' failed to build: OCI runtime create failed:
服务“返回”未能构建:OCI 运行时创建失败:
container_linux.go:370: starting container process caused: exec:container_linux.go:370:启动容器进程导致:exec:
"powershell": executable file not found in $PATH: unknown“powershell”:在 $PATH 中找不到可执行文件:未知
Now my guess is that I should install a powershell into container.现在我的猜测是我应该将 powershell 安装到容器中。
Any help would be highly appreciated.任何帮助将不胜感激。
I would say that your guess ( Now my guess is that I should install a powershell into container.
) is correct, yes:)我会说你的猜测(
Now my guess is that I should install a powershell into container.
)是正确的,是的:)
I had a similar problem and opted to replace the PowerShell command by a shell command, which ensures compatibility.我遇到了类似的问题,并选择用 shell 命令替换 PowerShell 命令,以确保兼容性。
However, if you cannot replace your PowerShell command by a suitable shell, then, you may use the PowerShell in Docker, following the documentation .但是,如果您无法用合适的 shell 替换您的 PowerShell 命令,那么,您可以在 ZC5FD2724CDD0D2B3B5420 之后的文档中使用 PowerShell。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.