簡體   English   中英

Change shell to git bash.exe in windows docker container

[英]Change shell to git bash.exe in windows docker container

我想從 git-for-windows 將 shell 更改為bash.exe

我有 docker 文件:

FROM mcr.microsoft.com/windows/servercore:1809

# $ProgressPreference: https://github.com/PowerShell/PowerShell/issues/2138#issuecomment-251261324
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

RUN iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN choco install -y git

RUN & 'C:/Program Files/Git/bin/sh.exe' -c "ls -al"  #### << Passes
SHELL ["\"C:\\Program Files\\Git\\bash.exe\"", "-c"] #### << Passes
RUN ls -al                                           #### << Crashes

第三條語句的結果: /usr/bin/bash: Files/Git/bin/sh.exe: No such file or directory

當我嘗試像下面這樣引用

SHELL ["\"C:\\Program Files\\Git\\bash.exe\"", "-c"]
RUN ls -al

構建工作,但我沒有看到任何來自ls -al的 output 我不知道它是否真的有效?

如何成功使用bash.exe 我正在通過 WSL2 引擎將 docker 用於 windows。

我在使用基本映像 mcr.microsoft.com/windows:2004 時遇到了類似的問題。 我對 windows 命令提示符或 powershell 不是很熟悉。

使用巧克力安裝 git 后,更新系統 PATH 環境變量。 我為此使用了 cmd ,因為這是我在堆棧溢出時發現的第一種方法並且它已經奏效了。 我沒有使用包含空格的路徑測試運行命令,因此下面的命令可能無法為您開箱即用。

SHELL ["cmd", "/S", "/C"]

RUN setx path "C:\\Program Files\\Git\\bin;%path%"

更新系統路徑環境變量后,bash.exe 在命令行可用。

SHELL ["bash.exe", "-c"]

RUN "ls -la"

ENTRYPOINT ["bash.exe"]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM