https://github.com/johanhaleby/docker-machine-port-forwarder
Simple bash script that makes it easier to forward ports from Docker Machine
https://github.com/johanhaleby/docker-machine-port-forwarder
docker docker-machine
Last synced: 9 months ago
JSON representation
Simple bash script that makes it easier to forward ports from Docker Machine
- Host: GitHub
- URL: https://github.com/johanhaleby/docker-machine-port-forwarder
- Owner: johanhaleby
- License: apache-2.0
- Created: 2016-04-08T06:13:47.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-05-20T06:25:59.000Z (about 7 years ago)
- Last Synced: 2025-04-02T04:11:28.271Z (about 1 year ago)
- Topics: docker, docker-machine
- Language: Shell
- Size: 7.81 KB
- Stars: 109
- Watchers: 4
- Forks: 21
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Docker Machine Port Forwarding
A small bash script that makes it easier to expose ports between [docker-machine](https://docs.docker.com/machine/) (VirtualBox or macOS hypervisor like [xhyve](https://github.com/machine-drivers/docker-machine-driver-xhyve), [HyperKit](https://github.com/machine-drivers/docker-machine-driver-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](http://code.haleby.se/2016/04/08/docker-machine-port-forwarding/).
## 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:
```bash
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.