I have the latest Docker Toolbox RC running on OS X (VirtualBox driver).
IP of Docker host is:
$ docker-machine ip
192.168.99.100
I'm running a container like this:
$ docker run -ti -p 4505:4505 my_image /bin/bash
[root@blah /]#
I've attempted to check whether I can access this port from an entirely different machine, running Windows 10, on my network:
$ nmap -p 4505 192.168.99.100
Starting Nmap 7.01 ( https://nmap.org ) at 2016-02-04 17:18 W. Europe Standard Time
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 0.74 seconds
How can I make the container and other machines on my network see each other?
Edit: the accepted answer below makes it possible to access the container on specified ports via the IP address of the physical machine. That is, you do not access the container via 192.168.99.100:4505
. Instead, it can be accessible via your machine's <IP>:4505
.
If you're using the VirtualBox driver with docker-machine to run a Docker VM on your Mac, then you can forward the port from your Mac to the VM like this:
VBoxManage controlvm myvirtualmachine natpf1 'myapp,tcp,,4505,,4505'
Let's break this down:
- VBoxManage is the name of the executable that controls VirtualBox.
- controlvm tells VirtualBox that you're telling a VM (rather than the VM manager) to do something.
- myvirtualmachine is the name of your Docker VM (you can find this by running
docker-machine ls
).
- natpf1 tells the VM to create a NAT port forward. This is where the magic starts to happen.
- 'myapp,tcp,,4505,,4505' is a list of arguments to natpf1:
- myapp is a name for the port forwarding rule. It's optional.
- tcp is the type of traffic you want to forward. The other option is udp
- There is room for a host IP at this point, but you can leave it blank.
- 4505 is the port on your Mac where you want to receive the traffic. This is the port number you would give to the other hosts on your network.
- There is room for a guest IP at this point, but you can leave it blank.
- The second 4505 is the port on your Docker VM where you want to receive the traffic. You can change this to whatever you like without affecting the first port. You would just have to change the port you expose from your Docker container.
You can find the official documentation for this command at https://www.virtualbox.org/manual/ch08.html#vboxmanage-controlvm