GithubHelp home page GithubHelp logo

johanhaleby / docker-machine-port-forwarder Goto Github PK

View Code? Open in Web Editor NEW
109.0 6.0 21.0 8 KB

Simple bash script that makes it easier to forward ports from Docker Machine

License: Apache License 2.0

Shell 100.00%
docker-machine docker

docker-machine-port-forwarder's Introduction

Docker Machine Port Forwarding

A small bash script that makes it easier to expose ports between docker-machine (VirtualBox or macOS hypervisor like xhyve, HyperKit etc.) and the host when using Docker Machine on macOS. The script is called pf which stands for "port forward". You can also read more on this blog.

Usage

$ pf 8080

Forwards port 8080 in the container to port 8080 on the host in docker-machine environment default by opening an SSH connection to VirtualBox in the background.

If you run into this error:

Host does not exist: "default"

you'll need to specify the name of your docker-machine environment. For example:

$ pf 8080 -e dev

This will use the dev docker-machine environment.

Stopping the port forwarding

If you've started port forwarding in the background (default) you can easily stop it using:

$ pf 8080 -s

Note that you don't need to specify an environment (-e) for this to work.

Port Mapping

You can map the docker port to another port on the host like this:

$ pf 8090:8080

This will map port 8090 on the host to port 8080 running in the container.

Foreground

You can also start the port forwarding process in the foreground:

$ pf 8080 -f

If you do this you'll see the docker-machine and once it's shutdown the port forwarding is also stopped automatically (i.e. no need to run pf 8080 -s).

Help

Run pf -h to for more options

Advanced

If you need more advanced options just use the vanilla docker-machine command. The purpose of pf is to make it really easy to do the most basic things.

docker-machine-port-forwarder's People

Contributors

falconepl avatar johanhaleby avatar mjbright avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

docker-machine-port-forwarder's Issues

When I'm running under root, I've got the error

When I'm running under root, I've got the error:

sudo pf 443
machine does not exist

It seems, sudo can't see the docker-machine. So, I'm usually solving the problem just connecting to docker-machine: docker-machine ssh default in one tab. In the other tab, I'm searching for the running process: ps aux | grep ssh. I've got something like that:

ivan             44949   0.0  0.1  4279248   5708 s003  S+    7:06PM   0:00.04 /usr/bin/ssh -F /dev/null -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=no -o ControlPath=none -o LogLevel=quiet -o PasswordAuthentication=no -o ServerAliveInterval=60 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [email protected] -o IdentitiesOnly=yes -i /Users/ivan/.docker/machine/machines/default/id_rsa -p 51651

Then I'm running the same command under root, but I'm adding -f -N -L 443:localhost:443:

sudo /usr/bin/ssh -F /dev/null -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=no -o ControlPath=none -o LogLevel=quiet -o PasswordAuthentication=no -o ServerAliveInterval=60 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [email protected] -o IdentitiesOnly=yes -i /Users/ivan/.docker/machine/machines/default/id_rsa -p 51651 -f -N -L 443:localhost:443

It would be nice if there will be the working solution in the script. Thanks ;)

No VirtualBox with Docker Toolkit

Previously, Docker machine is running as VirtualBox in MacOS. Currently, nope nope.

Any alternative? Or can we make two versions of this pf script?

Mention that the script is not VirtualBox-specific

The README mentions that pf is a script that exposes ports between VirtualBox and the host when it comes to docker-machine being used on macOS. However, pf works perfectly fine if someone uses any other hypervisor for Docker, such as xhyve, the native hypervisor for macOS - docker-machine-driver-xhyve. It should be the same case with HyperKit, another virtualization based on Hypervisor.framework introduced in macOS 10.10 - docker-machine-driver-hyperkit.

After analyzing the script it is obvious that pf is not VirtualBox dependent (as everything is done through docker-machine CLI), but I think it could be mentioned in the README.md as well. What do you think @johanhaleby?

And by the way - thanks for the script! Works like a charm.

How to bind to 0.0.0.0??

Great job.But I find that it's bind to 127.0.0.1 which can't be connected outside macOS.How can I make it bind to 0.0.0.0??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.