In the previous chapter (Networking - Port Forwarding), we set up a web server that we can access from our host machine. So, we can say that we have a fairly functional development environment. But in addition to providing a development environment box, Vagrant also makes it easy to share and collaborate on these environments. The primary feature to do this in Vagrant is called Vagrant Share.
Vagrant share has three main features:
- HTTP sharing creates a URL that will be routed directly into our Vagrant environment.
- SSH sharing allows instant SSH access to our Vagrant environment by anyone by running vagrant connect --ssh on the remote side.
- General sharing allows anyone to access any exposed port of our Vagrant environment by running vagrant connect on the remote side.
Before being able to share our Vagrant environment, we need an account on Vagrant Cloud.
Once we have an account, we can log in using vagrant login:
$ vagrant login In a moment we'll ask for your username and password to Vagrant Cloud. After authenticating, we will store an access token locally. Your login details will be transmitted over a secure connection, and are never stored on disk locally. If you don't have a Vagrant Cloud account, sign up at vagrantcloud.com Username or Email: firstname.lastname@example.org Password (will be hidden): You're now logged in! k@laptop:~/my_vagrant$
Now, it's share time, issue vagrant share command:
k@laptop:~/my_vagrant$ vagrant share ==> default: Detecting network information for machine... default: Local machine address: 127.0.0.1 default: default: Note: With the local address (127.0.0.1), Vagrant Share can only default: share any ports you have forwarded. Assign an IP or address to your default: machine to expose all TCP ports. Consult the documentation default: for your provider ('virtualbox') for more information. default: default: Local HTTP port: 4567 default: Local HTTPS port: disabled default: Port: 2222 default: Port: 4567 ==> default: Checking authentication and authorization... ==> default: Creating Vagrant Share session... default: Share will be at: ridiculous-frog-9978 ==> default: Your Vagrant Share is running! Name: ridiculous-frog-9978 ==> default: URL: http://ridiculous-frog-9978.vagrantshare.com ==> default: ==> default: You're sharing your Vagrant machine in "restricted" mode. This ==> default: means that only the ports listed above will be accessible by ==> default: other users (either via the web URL or using `vagrant connect`).
Let's copy the URL ("http://ridiculous-frog-9978.vagrantshare.com") that vagrant share outputted for us and visit that in a web browser. It should load the index page we setup in the previous chapter:
Now, modify our index.html file and refresh the URL. It will be updated! That URL is routing directly into our Vagrant environment:
To end the sharing session, hit Ctrl+C in our terminal. We can refresh the URL again to verify that our environment is no longer being shared.
k@laptop:~/my_vagrant$ vagrant share ==> default: Detecting network information for machine... ... ==> default: You're sharing your Vagrant machine in "restricted" mode. This ==> default: means that only the ports listed above will be accessible by ==> default: other users (either via the web URL or using `vagrant connect`). ^CExiting due to interrupt.
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization