Ruby的Docker卷挂载问题

时间:2019-04-10 09:23:18

标签: ruby docker

我有一个测试用例,其中在Windows docker容器中运行Ruby实例。我应该强调一下,Ruby脚本在docker之外还可以正常工作。当在docker容器中运行时,该脚本也可以正常工作,除非Ruby文件的访问目标位于已装载的卷上。在这种情况下,我会报错。对于测试用例,我当然可以通过复制文件来解决此问题,但这会给发现此问题的真实脚本带来麻烦。

这是一个示例脚本,cbh_test是已装载的卷

PS C:\> echo ""> bob
PS C:\> cp cbh_test\failer.rb .
PS C:\> C:\Ruby25-x64\bin\ruby.exe .\failer.rb
PS C:\> cd cbh_test
PS C:\cbh_test> echo ""> bob
PS C:\cbh_test> C:\Ruby25-x64\bin\ruby.exe .\failer.rb
Traceback (most recent call last):
./failer.rb: Invalid argument @ rb_readlink - C:/cbh_test (Errno::EINVAL)

Docker实例通过以下方式调用:

docker run -it -v c:\Users\me\work\fred:c:\cbh_test  bob/failer  powershell

Dockerfile:

# escape=`
FROM microsoft/windowsservercore:ltsc2016
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
COPY install_ruby.ps1 c:
RUN powershell c:\install_ruby.ps1

failer.rb:

def main(args)
    fragment = "bob"
    $tmp = File.open(File.join(File.dirname(__FILE__), fragment), 'r+').read      
end
main($ARGV)

install_ruby.ps:

$RUBY_VERSION = "2.5.3-1"
$RUBY_RELEASE =  "2.5.3-1"


$url = ('https://github.com/oneclick/rubyinstaller2/releases/download/rubyinstaller-{0}/rubyinstaller-{1}-x64.exe'-f $RUBY_VERSION, $RUBY_RELEASE);
$exe = "ruby-install.exe"

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
Invoke-WebRequest -Uri $url -OutFile $exe; 
$args = "/silent /tasks='assocfiles,modpath'"
Start-Process -FilePath $exe -ArgumentList $args -PassThru -Wait 

1 个答案:

答案 0 :(得分:-1)

我尝试了几天,唯一能够解决此问题的解决方案是使用ltsc2019。