msys2 / MSYS2-packages

Package scripts for MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
1.29k stars 485 forks source link

MSYS2 programs do not output to console inside interactive TTY Windows Docker container #1490

Open filipesilva opened 5 years ago

filipesilva commented 5 years ago

Heya,

I'm trying to setup MSYS2 inside a Windows Docker container, and it looks like there might be a problem between interactive TTY docker sessions and MSYS program output. The original issue I found for this problem is https://github.com/docker/for-win/issues/262.

You can reproduce this by following these steps:

C:>C:\msys64\usr\bin\bash.exe -c "echo hello" C:\msys64\usr\bin\bash.exe -c "echo hello" hello

- But running it inside an interactive TTY (`-it` flag) container shows no output. If I pipe the output to a file I can see it though.

C:>docker run --rm -it -v C:\msys64:C:\msys64 stefanscherer/node-windows:10.13.0-build-tools cmd Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved.

C:>C:\msys64\usr\bin\bash.exe -c "echo hello"

C:>C:\msys64\usr\bin\bash.exe -c "echo hello" > debug.txt

C:>type debug.txt hello



In https://github.com/docker/for-win/issues/262#issuecomment-311845385 it was mentioned that this behaviour might be related to how MSYS2 uses stdio pipes, but I don't know if this is accurate.

I hope this is somehow fixable between MSYS2 and Docker, and thanks for the good work in MSYS2!
manvscode commented 4 years ago

Any progress with this defect?

mabrarov commented 4 years ago

I do not face this issue on Windows Server 2019 1809 with Docker 19.03:

PS C:\Users\Administrator> [System.Environment]::OSVersion.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      17763  0

PS C:\Users\Administrator> docker version
Client: Docker Engine - Enterprise
 Version:           19.03.1
 API version:       1.40
 Go version:        go1.12.5
 Git commit:        f660560464
 Built:             07/25/2019 20:59:52
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Enterprise
 Engine:
  Version:          19.03.1
  API version:      1.40 (minimum version 1.24)
  Go version:       go1.12.5
  Git commit:       f660560464
  Built:            07/25/2019 20:57:41
  OS/Arch:          windows/amd64
  Experimental:     false
PS C:\Users\Administrator> docker run --rm -it abrarov/windows-dev:2.8.0 C:\msys64\usr\bin\bash.exe -c "echo hello"
hello
PS C:\Users\Administrator> docker run --rm abrarov/windows-dev:2.8.0 C:\msys64\usr\bin\bash.exe --version
GNU bash, version 4.4.23(1)-release (x86_64-pc-msys)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

But I reproduce this issue with Windows Server 2016 1607 and Docker 17.06:

PS C:\Users\Administrator> [System.Environment]::OSVersion.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      14393  0

PS C:\Users\Administrator> docker version
Client:
 Version:      17.06.2-ee-23
 API version:  1.30
 Go version:   go1.10.8
 Git commit:   f9a8679
 Built:        Tue Jul 16 16:47:38 2019
 OS/Arch:      windows/amd64

Server:
 Engine:
  Version:      17.06.2-ee-23
  API version:  1.30 (minimum version 1.24)
  Go version:   go1.10.8
  Git commit:   f9a8679
  Built:        Tue Jul 16 16:55:49 2019
  OS/Arch:      windows/amd64
  Experimental: false
PS C:\Users\Administrator> docker run --rm -it abrarov/windows-dev:2.5.0 C:\msys64\usr\bin\bash.exe -c "echo hello"
PS C:\Users\Administrator> docker run --rm abrarov/windows-dev:2.5.0 C:\msys64\usr\bin\bash.exe --version
GNU bash, version 4.4.23(1)-release (x86_64-pc-msys)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

I have to use different docker images for these tests because different versions of Windows require different version of base docker image (mcr.microsoft.com/windows/servercore:ltsc2019 vs microsoft/windowsservercore:ltsc2016)

IMHO, this issue is related to Windows Containers, i.e. is fixed in Windows Server 2019 but won't be fixed in Windows Server 2016, because it doesn't look like MS cares about Windows Containers for Windows Server 2016.

Taking into account the fact that on Windows Server 2016 application inside container is just killed when container stops (docker stop), I do not see possibility to use Windows Containers (docker) on Windows Server 2016. This issue is fixed in Windows Server 2019.

If I'm correct with my findings (if smbd could confirm the same), then I vote for closing this issue as issue not related to MSYS2, but related to Windows Containers in Windows Server 2016.

manvscode commented 4 years ago

@mabrarov I had a break-through. It seems like it's broken if I use mcr.microsoft.com/dotnet/framework/sdk:latest as a base image.

This image has the .net framework 4.8 and build tools 2019 installed. It would seem like the most appropriate image to use for CI for windows applications.

fralalonde commented 3 years ago

In case it helps someone debug this: I have this same behavior (no console output) when my dotnet app is run from MSYS's zsh. Running the app from bash works fine.

dortamiguel commented 3 years ago

@fralalonde it happens to me too with normal bash and zsh when using windows terminal

If I use the Mintty terminal that comes with the msys2 isntaller the output works

For reference, this is how I start msys2 from windows terminal

{
  "commandline": "C:/msys64/msys2_shell.cmd -defterm -no-start -mingw64",
  "guid": "{17da3cac-b318-431e-8a3e-7fcdefe6d115}",
  "name": "bash",
  "startingDirectory": "%USERPROFILE%"
},