windows - 无法在 Windows Docker 容器中运行 cygwin

标签 windows shell docker cygwin

我一直在使用 Docker for Windows,试图创建一个 Windows 容器,该容器可以在容器本身内将 cygwin 作为 shell 运行。我还没有运气让这一切顺利进行。这是我一直在搞乱的 Dockerfile。

# escape=`
FROM microsoft/windowsservercore

SHELL ["powershell", "-command"]

RUN Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression
RUN choco install cygwin -y
RUN refreshenv
RUN [Environment]::SetEnvironmentVariable('Path', $env:Path + ';C:\tools\cygwin\bin', [EnvironmentVariableTarget]::Machine)

我尝试设置 ENTRYPOINT 和 CMD 以尝试进入 cygwin,但似乎都没有做任何事情。我还使用 docker run -it 附加到容器并启动了 cygwin 命令以进入 shell,但它似乎没有做任何事情。我没有收到错误,它只是返回到命令提示符,就好像什么都没发生一样。

是否可以在 Windows 容器中运行另一个 shell,或者我只是做错了什么?

谢谢!

最佳答案

您不会使用 docker run “附加”到容器:您使用它启动容器。

在你的情况下,如 seen here , docker run -it 是正确的做法。

您可以尝试使用 c:\cygwin\bin\bash 作为入口点,如 in this issue 所示.

正如 issue 32330 中的评论:

Don't get me wrong, cygwin should work in Docker Windows containers.

But, it's also a little paradoxical that containers were painstakingly wrought into Windows, modeled on containers on Linux, only for people to then want to run Linux-utils in these newly minted Docker Windows containers...

同样的问题仍未解决,2018 年 5 月和 6 月出现新案例:

We have an environment that compiles with Visual Studio but still we want to use git and some very useful commands taken from linux.
Also we use of-the-shelve utilities (e.g. git-repo) that uses linux commands (e.g. curl, grep,...)

Some builds require Cygwin like ICU (a cross-platform Unicode based globalization library), and worst: our builds require building it from source.


您可以在 MSYS2-packages issue 1239 中查看崩溃示例:

Step 5/5 : RUN "C:\\msys64\\usr\\bin\\ls.exe"
 ---> Running in 5d7867a1f8da
The command 'cmd /S /C "C:\\msys64\\usr\\bin\\ls.exe"' returned a non-zero code: 3221225794

这可以获得更多关于崩溃的信息:

PS C:\msys64\usr\bin> 
  Get-EventLog -Index 28,29,30 -LogName "Application" | Format-List -Property *

The workaround是:

PS > xcopy /S C:\Git C:\Git_Copy
PS > C:\Git_Copy\usr\bin\sh.exe --version > v.txt
PS > type v.txt

As mentioned in that thread, the output gets lost somewhere in the container, thus sending it to a text file.

关于windows - 无法在 Windows Docker 容器中运行 cygwin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43123851/

相关文章:

linux - 文件监控 Bash 脚本

linux - Bash:一次有两个 for 循环?

ssl - 带有外部证书的 Docker Datacenter : Error x509 certificate signed by unknown authority UCP 2. 0.0 和 DTR 2.1.0

amazon-web-services - 如何在 terraform 中将主机目录绑定(bind)到 ECS

RHEL 8 上的 Docker 使用 027 权限创建文件和文件夹

c++ - CUDA内核作为类的成员函数

与 Windows 相比,Linux 上的代码速度较慢

windows - 如何在 Matlab 编译器生成的 exe 的高 DPI 设置上禁用显示缩放

c++ - 从另一个应用程序在 Cygwin 中运行 bash 命令

c - Pipe() 系统调用