使用Docker提供程序的Vagrant:指定CPU和内存

时间:2017-12-21 06:41:54

标签: docker vagrantfile

我使用Vagrant创建了几个Docker容器。除了我无法控制容器的CPU和内存分配外,一切似乎都运行良好。下面你可以看到几次失败的尝试。

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.ssh.insert_key = false

  config.vm.provider "docker" do |d|
    d.build_dir = "."
    d.force_host_vm = false
    d.has_ssh = true
#    d.cpus = "2"           # works for vbox not docker
#    d.memory = "4096"      # same      
    d.create_args = [ "--privileged", "-v", "/sys/fs/cgroup:/sys/fs/cgroup:ro" ]
    d.customize ["modifyvm", :id, "--cpus", "2"]            # Also throws error
    d.customize ["modifyvm", :id, "--memory", "4096"]       # same
    d.remains_running = true
  end


  config.vm.define :c7301 do |c7301|
    c7301.vm.hostname = "c7301.ambari.apache.org"
    c7301.vm.network :private_network, ip: "192.168.73.101"
    c7301.vm.network "forwarded_port", guest:7180, host: 7180
  end

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

这对我有用:

  config.vm.provider :docker do |d|
    d.build_dir = "."
    d.remains_running = true
    d.has_ssh = true
    # configure docker container 
    d.create_args = ['--cpuset-cpus=2']
    d.create_args = ['--memory=6g']
  end

here得到提示,然后 可用的码头工人options