Runing bash in a Windows container

Has anyone succeeded in running the Unix style “bash” shell in a Windows flavor container? (In other words: so that it can run Windows executables.)

I was hoping for msys2 to help me out, but as far as I have found until now, there is no way to run the installer in CLI mode, so I can’t have it installed.

I can install it on my desktop Windows PC and try to copy the installation into the Docker image, but the container crashes when I start it. I guess I see the reason: When it opens, it insists on running the bash shell in a new window, which can’t be done from a Docker container.

So has anyone out there succeeded in running any variant of bash in a container?

(What I am really after is a shell that can run Windows executables and has support for long filenames. It doesn’t necessarily have to be bash, but msys2 bash satisfies requirements on the desktop - I just can’t seem get it to work in a container!)

I’ve managed to get an image to build, I used the Windows Chocolatey image:

FROM chocolatey/choco:latest-windows
RUN choco install git --version 2.39.2 --yes

RUN choco install jq --version 1.6 --yes
RUN choco install python --version 3.11.0 --yes
RUN choco install unzip --version 6.0 --yes
RUN choco install curl --version 7.88.1 --yes
RUN choco install sudo --version 1.1.3 --yes
RUN choco install awscli --version 2.11.2 --yes

# Append additional git directories to PATH
ENV ADD_PATH=";C:\Program Files\Git\usr\bin;C:\Program Files\Git\bin"
# Update Registry key to append the above entries to PATH
RUN PowerShell Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value ((Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path + "$Env:ADD_PATH")

As you can see i’ve installed git, which comes with git bash, and I made sure I added the additional git directories to the PATH.

When I ran the container interactively using docker run -it <my-image> PowerShell

I can see that PATH is set correctly, and that the other tools, such as git itself etc. are all available:

PS C:\> git --version
git version 2.39.2.windows.1

however weirdly bash itself just doesn’t seem to work at all, returning a non-zero exit code, no matter what arguments I give it:

PS C:\> git --version
git version 2.39.2.windows.1
PS C:\> $LastExitCode
0
PS C:\> bash --version
PS C:\> $LastExitCode
-1073741502
PS C:\>

So i’m struggling to work out why this isn’t working for me. Everything else seems to work (and git bash installed via chocolately on my local machine works fine)