Users of Vagrant can upload their base boxes to Vagrant Cloud, making them available to the public, or they can use a paid account to publish boxes privately to their own teams.
- [Instructor] Sharing boxes with the public is made possible by Vagrant Cloud. Open a browser and go to app.vagrantup.com. Click the Create and Account button and create a free personal account. I'll use my devopskatas account to demonstrate. After your account is created, you'll be taken to a page where you can search or upload your own box. From the Dashboard, click New Vagrant Box. The next page will ask you to name the box. I'll use myfirstbox.
The organization name will be your account name. Leave the Private box unchecked. Private boxes require a paid Vagrant Cloud account. Enter a short description, and then click Create box. The next page will ask for a box version. Vagrant Boxes are versioned using semantic versioning, which is a structured method for versioning software. We'll set our box version to 0.0.1 to indicate that it is the first ever release of this box.
In the description, enter First release of myfirstbox. And click Create version. This box is now created in Vagrant Cloud, but it has no providers and is not released. The next step is to create a box file for upload. Leave this page open in your browser. Open a new tab, and go to github.com/dswersky/vagrant_cloud. Clone this repository to your local user profile directory, or you could select the Vagrant Cloud directory from the exercise files, if you prefer.
Open the vagrant_cloud directory with VS Code, and then open the integrated terminal. Open the Vagrant file. The Vagrant file included in this exercise is an Ubuntu 16.04 box with provisioners that install the NGINX webserver and port forwarding configuration to forward guest port 80 to host port 8080. In the terminal window, execute vagrant up. After the box has started, execute this command, vagrant package --vagrantfile vagrant_file/vagrantfile - -output myfirstbox.box.
Hit Enter, and the vagrant package command will create a new box from the current state of the running box. The box will be shut down, and Vagrant will use VirtualBox to create the files needed for a new box. When this command is complete, you'll have a new file in the environment directory called myfirstbox.box. And now our package command is complete, and we have the myfirstbox.box file in the environment. Return to the browser and go back to Vagrant Cloud. If your session has expired, log back into Vagrant Cloud with the account you created earlier, and select your myfirstbox.
The next step is to add a provider to the box you just created in Vagrant Cloud. We're working with VirtualBox, so we'll add that provider. Click the Add a provider button. In the next page, select VirtualBox from the dropdown. In the File Hosting section, make sure Upload to Vagrant Cloud is selected, then click Continue to upload. In the next page, click the Choose File button, then select the myfirstbox.box file that was created with the vagrant package command.
The file will begin uploading when you select it. This may also take some time to complete, depending on the speed of your Internet connection. When the upload is complete, click the myfirstbox link above to return to the box listing. This box now has a provider with an associated box file that was just uploaded. Now all you have to do is release this version. Click the release button, and then click Release version in the next page. Your box is now published to the public Vagrant Cloud.
Let's test your new box. Open a power shell or terminal window. And now execute cd space tilde, to go to your user profile directory, mkdir vagrantcloud. cd vagrantcloud, vagrant init. And now you'll use the account name that you used when you created your account, mine is devopskatas here, so I will use that, forward slash, myfirstbox.
That will create our Vagrant file. And now finally, vagrant up. The vagrant up command will locate your box on Vagrant Cloud, download it and add it to your local box cache. Vagrant will then import the box to this environment directory, and start it. You can use vagrant box list to see your box listed in the local box cache. Now that the box has started, I can use vagrant box list to list the boxes in the cache.
And we can see that devopskatas/myfirstbox is listed. The Vagrant file package with the box sets the default port forwarding settings so you don't have to set them in the local Vagrant file. When the box is started, you should be able to go to a browser, and select localhost:8080 and see the NGINX default page. As you iterate over the development of a box, you can return to its page in Vagrant Cloud, and create new versions by clicking New Version. Users of your boxes can access old versions by number if you choose to keep them available.
You can also add multiple providers to a version making that version compatible with other hypervisors, such as VMware and Hyper-V.
- What is Vagrant?
- Running your first box
- Connecting to a box
- Working with Vagrant Cloud
- Configuring boxes with Vagrantfiles
- Creating a developer environment
- Uploading a box to Vagrant Cloud