Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pr3sto/vagrant-port-range
Vagrant plugin for mapping forwarded ports using range of host ports
https://github.com/pr3sto/vagrant-port-range
vagrant vagrant-plugin
Last synced: about 1 month ago
JSON representation
Vagrant plugin for mapping forwarded ports using range of host ports
- Host: GitHub
- URL: https://github.com/pr3sto/vagrant-port-range
- Owner: pr3sto
- License: mit
- Created: 2017-12-17T16:22:54.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-17T08:09:00.000Z (about 6 years ago)
- Last Synced: 2024-11-14T13:42:49.480Z (about 1 month ago)
- Topics: vagrant, vagrant-plugin
- Language: Ruby
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vagrant-port-range
[![Gem Version](https://badge.fury.io/rb/vagrant-port-range.svg)](https://badge.fury.io/rb/vagrant-port-range)
vagrant-port-range is a Vagrant plugin for mapping forwarded ports using range of host ports.
## Installation
```console
foo@bar:~$ vagrant plugin install vagrant-port-range
```## Usage
The plugin is loaded automatically once installed.
## Configuration
### config.portrange.forwarded_port
Use [standart options from forwarded_port](https://www.vagrantup.com/docs/networking/forwarded_ports.html), except for next options:
* Instead of **host** use **host_range** with desired port range. Plugin will automatically pick free port from given range and insert it into **host** option.
* **attempts** - number of attempts for plugin to try get free port from given range. Plugin will try to randomly pick port and check whether it is free or not.## Example
Vagrantfile:
```ruby
# -*- mode: ruby -*-
# vi: set ft=ruby :Vagrant.configure("2") do |config|
config.portrange.forwarded_port guest: 6901, host_range: [3000, 4100], attempts: 10
config.portrange.forwarded_port guest: 8080, host_range: [3000, 4100], attempts: 10
config.vm.provider "docker" do |d|
d.image = "consol/ubuntu-xfce-vnc"
end
end```
The result:
```console
foo@bar:~$ vagrant upBringing machine 'default' up with 'docker' provider...
==> default: [vagrant-port-range] Free port found: 4022
==> default: [vagrant-port-range] Free port found: 3744
==> default: Creating the container...
default: Name: vagrantportrange_default_1514061829
default: Image: consol/ubuntu-xfce-vnc
default: Port: 4022:6901
default: Port: 3744:8080
default:
default: Container created: b01667fcb339703a
==> default: Starting container...foo@bar:~$
```In case of situation when all ports from range are in use:
```ruby
# -*- mode: ruby -*-
# vi: set ft=ruby :Vagrant.configure("2") do |config|
config.portrange.forwarded_port guest: 6901, host_range: [80, 81], attempts: 10
config.vm.provider "docker" do |d|
d.image = "consol/ubuntu-xfce-vnc"
end
end```
```console
# make them busy
foo@bar:~$ python3 -m http.server 80
foo@bar:~$ python3 -m http.server 81foo@bar:~$ vagrant up
Bringing machine 'default' up with 'docker' provider...
==> default: [vagrant-port-range] Free port from range [80, 81] not foundfoo@bar:~$
```