4

I'm using Vagrant to create several Docker containers. Everything seems to work well except I can't control CPU and memory allocation to the containers. Below you can see a couple of failed attempts.

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

Any advice?

zenlc2000
  • 451
  • 4
  • 9
  • Did you try it in `create_args` itself? You need to pass these `--cpus` and `--memory` parameter as a part of it and not use `d.customize` – Tarun Lalwani Dec 21 '17 at 07:15
  • I did try it, but I think for some reason I just added a second create_args. In the morning I'll try the options in the existing create_args. – zenlc2000 Dec 21 '17 at 08:07

1 Answers1

3

This worked for me:

  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

Got it hint from here and available docker options

Javed
  • 5,904
  • 4
  • 46
  • 71