Ruby docker-api来挂载音量

如何在运行时使用ruby docker-api( https://github.com/swipely/docker-api )将主机卷挂载到docker中?

基本上, docker run -v path:path这个gem的docker run -v path:pathfunction。

目前的README错过了关于如何在容器中使用卷的部分。 你可以用下面的命令运行容器的文件夹/foo

 container = Docker::Container.create('Cmd' => %w[test -d /foo], 'Image' => 'debian:wheezy', 'Volumes' => {'/foo' => {}} ) 

如果您需要使用本地文件夹进行装载,请更新到Volumes' => {'/foo' => '/local_foo'}您可以参考以下testing用例:

container_spec.rb

docker -api gem的文档在README.md中声明 :

 require 'docker' # Create a Container. container = Docker::Container.create('Cmd' => ['ls'], 'Image' => 'base') # Attach to the Container. Currently, the below options are the only valid ones. # By default, :stream, :stdout, and :stderr are set. container.attach(:stream => true, :stdin => nil, :stdout => true, :stderr => true, :logs => true, :tty => false) # => [["bin\nboot\ndev\netc\nhome\nlib\nlib64\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nselinux\nsrv\nsys\ntmp\nusr\nvar", []] # If you wish to stream the attach method, a block may be supplied. container = Docker::Container.create('Image' => 'base', 'Cmd' => ['find / -name *']) container.tap(&:start).attach { |stream, chunk| puts "#{stream}: #{chunk}" } stderr: 2013/10/30 17:16:24 Unable to locate find / -name * # => [[], ["2013/10/30 17:16:24 Unable to locate find / -name *\n"]] # If you want to attach to stdin of the container, supply an IO-like object: container = Docker::Container.create('Image' => 'base', 'Cmd' => ['cat'], 'OpenStdin' => true, 'StdinOnce' => true) container.tap(&:start).attach(stdin: StringIO.new("foo\nbar\n")) # => [["foo\nbar\n"], []] 

这有帮助吗? 我可以问你为什么要使用docker-api ? 你不能只使用docker卷(-v) ?