如何在运行时使用ruby docker-api (https://github.com/swipely/docker-api)将主机卷挂载到docker中?
基本上,这个gem的docker run -v path:path
功能。
发布于 2016-05-10 20:48:02
当前的README
缺少解释如何将卷与容器一起使用的部分。使用容器的文件夹/foo
运行下面的命令应该没问题
container = Docker::Container.create('Cmd' => %w[test -d /foo],
'Image' => 'debian:wheezy',
'Volumes' => {'/foo' => {}}
)
如果您需要使用本地文件夹挂载,请更新到Volumes' => {'/foo' => '/local_foo'}
您可以从以下位置参考测试用例:
发布于 2016-05-10 19:47:21
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 volumes (-v)吗
发布于 2018-05-10 21:06:10
使用Binds
'Binds' => ['/local/folder:/container/folder']
https://stackoverflow.com/questions/37135696
复制相似问题