Colema18
Colema18

Reputation: 491

vagrant package creates a copy of the original box with no changes I have made

This may be a noob question, but after making some changes to an image with vagrant up and then installing something, I then call vagrant package --box [name] --output [new.box].

After I create a new vagrant init from new.box, it doesn't have the new things I installed on the box that I packaged.

Anyone know what I am doing wrong?

Upvotes: 0

Views: 774

Answers (1)

Radek Simko
Radek Simko

Reputation: 16126

The reason could be that you used the same box name.

As you described, you've done something like this:

  1. Created a Vagrantfile:

    Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
      config.vm.box = 'base'
      config.vm.box_url = 'http://the-url-of-box-you-used-as-base.com/precise.box'
    end
    
  2. vagrant up

  3. vagrant ssh => there you've made some changes
  4. vagrant package --box [name] --output [new.box]
  5. Edit the original Vagrant file (or create a new one) to load your new box:

    Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
      config.vm.box = 'base'
      config.vm.box_url = 'my-new.box'
    end
    

And here I'm assuming you kept the config.vm.box the same, which means Vagrant didn't use your box, but the original previous box as there's already downloaded box with that name in your ~/.vagrant.d/boxes.

There might be two solutions:

  1. Change the name in Vagrantfile (if you have actually used different name when generating custom box)
  2. Delete cached box with that name = remove ~/.vagrant.d/boxes/[name]

Upvotes: 1

Related Questions