Skip to content

Instantly share code, notes, and snippets.

@randerzander

randerzander/portbind.py

Last active Aug 29, 2015
Embed
What would you like to do?
python script for binding boot2docker-vm ports to localhost
#!/usr/bin/python
import sys
from subprocess import Popen, PIPE
from subprocess import call
container_id = sys.argv[1]
p = Popen(['docker', 'port', container_id], stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, err = p.communicate()
rc = p.returncode
def run(command):
print command
call(command.split(' '))
for line in output.split('\n'):
if len(line) > 0:
container_port = line.split('/')[0]
vm_port = line.split(':')[1]
run('VBoxManage controlvm boot2docker-vm natpf1 delete tcp'+container_port)
run('VBoxManage controlvm boot2docker-vm natpf1 tcp'+container_port+',tcp,,'+container_port+',,'+vm_port)
@randerzander

This comment has been minimized.

Copy link
Owner Author

@randerzander randerzander commented Jul 17, 2015

Usage: python portbind.py container_id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.