无法在Windows Docker容器中运行cygwin [英] Unable to run cygwin in Windows Docker Container

查看:70
本文介绍了无法在Windows Docker容器中运行cygwin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在与Docker for Windows合作,试图创建一个Windows容器,该容器可以将cygwin作为容器本身的外壳运行.我还没有走运的运气.这是我一直在处理的Dockerfile.

I've been working with Docker for Windows, attempting to create a Windows Container that can run cygwin as the shell within the container itself. I haven't had any luck getting this going yet. Here's the Dockerfile that I've been messing with.

# 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,但它似乎无能为力.我没有收到错误,它只是返回到命令提示符,好像什么都没发生.

I've tried setting the ENTRYPOINT and CMD to try and get into cygwin, but neither seems to do anything. I've also attached to the container with docker run -it and fired off the cygwin command to get into the shell, but it doesn't appear to do anything. I don't get an error, it just returns to the command prompt as if nothing happened.

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

Is it possible to run another shell in the Windows Container, or am I just doing something incorrectly?

谢谢!

推荐答案

长时间使用后,我的发现如下:

After playing with it for a long time, my findings were the following:

  • If your Cygwin utilities are crashing your container, you need to use process isolation. See https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility for the requirements (essentially you need to use Windows Server 2016 and a build-matching Docker Image). I spent some time trying to understand the reason why hyper-v isolation doesn't work and so far I didn't come to any conclusion;

如果您的Cygwin实用程序显然什么也不做-但它们不会使容器崩溃-您需要删除-t标志(-i标志仍然可以),或者使用stdout重定向播放.显然,当处理一些伪tty时,MSYS2似乎存在问题.如果将stdout重定向到文件,则可以验证程序是否仍在运行(例如,在不进行任何stdout重定向的情况下运行whoami时,whoami不会输出任何内容,但是whoami> out.txt会将预期结果输出到文件中).可以通过替换伪tty来解决此问题,但我没有尝试过.我怀疑问题出在MSYS2库中某个地方的句柄无效-因为其他控制台应用程序可以将内容打印到终端-但我没有对此进行验证.

If your Cygwin utilities apparently do nothing - but they don't crash the container - you need to remove the -t flag (the -i flag is still ok) or alternatively play with stdout redirection. Apparently there seems to be an issue with MSYS2 when it deals with some pseudo-ttys. You can verify that programs still run if you redirect stdout to a file (e.g. whoami won't output anything when you run it without any stdout redirection, but whoami > out.txt will output the expected result to a file). It might be possible to fix this by replacing the pseudo-tty but I didn't try it. I suspect that the problem is an invalid handle somewhere inside the MSYS2 libs - as other console apps can print things to the terminal - but I didn't verify this.

希望它可以帮助所有人遇到相同的问题.

Hope it helps to all of you having the same problem.

这篇关于无法在Windows Docker容器中运行cygwin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆