How to package synced folder in vagrant box

2019-06-24 03:26发布

What I want and achieved so far: I want to create a custom vagrant box including a configuration and an application to reuse it in different client or serve environments.

Specifically I managed to create vagrant box, based on Ubuntu (precise/64), that has node.js installed, and package it on my dev machine with

vagrant package my-box --output filename.box

I am able to copy the filename.box to a remote server and vagrant up the box there. Node.js is installed within the vagrant box as expected.

The problem is, that I am not able to package the files in the synced folder vagrant. After starting the box on the remote server, the synced folder is empty

Therefore the application I developed on the local machine is not included in the box.

I tried to find a solution or any information about this behavior, but apart from this unanswered Post i couldn't find anything on the net.

My questions:

  1. How can i preserve the files in the synced folder and package them in the filename.box for reuse in the server environment.
  2. Is this even possible? Is the behavior I see a bug or is Vagrant not meant to package the files also?
  3. I didn't do any configuration for the synced folders so far. Is it possible to package files from a different synced folder than the regular /vagrant?
  4. If this is not possible at all, what are best practices for deployment or reusage of vagrant environments including applications?

2条回答
我命由我不由天
2楼-- · 2019-06-24 03:28

1-3) No. This is not possible and not intended to work in the way you expect it to work. Think of VirtualBox's shared folder as a mounted volume on a remote machine. It's not part of the file system of your virtual machine. The actual data is saved on the host machine, not the virtual one.

4) If you want to add data into your box, just copy your data over to the vm before you pack it. No need to use shared folders.

查看更多
Bombasti
3楼-- · 2019-06-24 03:36

You cannot package a synced folder but what you are desiring is absolutely possible.

The easiest way to accomplish this is to put the data in some other directory in the box (thus ensuring it gets packaged with the box). And during the Vagrant box's provisioning, move or copy the data to the synced directory.

Once the box is up and running, the synced directory will have the files you want in it.

查看更多
登录 后发表回答