在windows docker容器中将shell改为git bash.exe



我想从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的任何输出,我不知道它是否真的有效?

如何成功使用bash.exe?我通过WSL2引擎在windows上使用docker。

我在使用base image mcr.microsoft.com/windows:2004时遇到了类似的问题。我对windows命令提示符和powershell不是很熟悉。

使用chocolatey安装git后,更新系统PATH环境变量。我使用cmd,因为这是我在堆栈溢出上发现的第一种方式,它已经工作了。我还没有使用包含空格的路径测试run命令,所以下面的命令可能无法为您开箱运行。

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"]

最新更新