docker-machine osx port forwarding - docker

How does port forwarding work with docker-machine?
I recently installed the docker toolkit and spun up a container. However I cannot reach it on my local mac as.
Is this Port forwarding in docker-machine? using VBoxManage the best way to access the running docker container using my OSX browser?

To add port forwards from the command line to a running boot2docker VM use the following command:
VBoxManage controlvm boot2docker-vm natpf1 "default,tcp,127.0.0.1,1234,,1234"

After restarting kitematic & the docker-host default VM. The container appeared in kitematic and the bound URL.

Related

Accessing docker container from Docker for Mac

I have the following scenario:
Mac OS Catalina
Windows Virtual Machine running on VirtualBox
Docker for Mac (not docker-machine or Docker Toolbox)
I need to access a port that is exposed with docker run -p 80:80 nginx from the Windows VM and nothing seems to work. I tried NAT, bridge, socat... any hints?
Ah, I figured it out.
I can access the docker service by using the bridge interface IP (but not using localhost).
So in essence:
VM in VirtualBox should run in network bridged mode
use http://1.2.3.4 in the browser where 1.2.3.4 is your MacOS network interface IP address

Equivalent to boot2docker ip for new docker for windows10/hyperV

I have used docker toolbox in the past on windows with Virtualbox and boot2docker. Now I installed new docker windows and boot2docker is not recognized anymore when typing
boot2docker ip
What command should I use now for Docker Windows ?
It should be localhost. Docker for Windows (as well as Docker for Mac) are doing some additional magic proxying to automatically forward ports from the host to the IP address of the VM so you shouldn't need to know the IP.
However, there are some caveats on Windows. Check out https://docs.docker.com/docker-for-windows/troubleshoot/#limitations-of-windows-containers-for-localhost-and-published-ports for more information if you are using Windows containers.

docker running splash container but localhost does not load (windows 10)

I am following this tutorial to use splash to help with scraping webpages.I installed Docker toolbox and did these two steps:
$ docker pull scrapinghub/splash
$ docker run -p 5023:5023 -p 8050:8050 -p 8051:8051 scrapinghub/splash
I think it is running correctly, based on the prompted message in Docker window, which looks like this:
However, when I open the `localhost:8050' in a web browser, it says the localhost is not working.
What might have gone wrong in this case? Thanks!
You have mapped the port to your docker host (the VM), but you have not port-forwarded that same port to your actual "localhost" (your Windows host)
You need to declare that port-forwarding in the Network settings of your VM (for instance "default"), or with VBoxManage controlvm commands.
Then and only then could you access that port (used by your VM) from your Windows host (localhost).
That or you can access that same port using the IP address of your boot2docker VM: see docker-machine ls.
#user3768495, when you use http://192.168.99.100:8050/ , you are actually using the docker-machine ip and this ip would be available on your machine only and not on the network. To map it to localhost, you do need to port-forward the same port to your localhost. I was having the same issue and I detailed the process in below link.
https://stackoverflow.com/a/35737787/4820675

How do I forward a docker-machine port to my host port on OSX?

I’m delivering a private docker container in my company and want my colleagues to be able to access in our internal network, the problem is that my guest OS is OSX and as so I can only access my application using the 192.168.99.100:3000 default ip from docker machine.
How can I forward the docker-machine 3000 port to my host 80 port?
At this time Docker Machine is a virtual machine running under VirtualBox in your machine, so to expose your application port you need to map your virtual machine port to your host port.
To achieve this there are two options, but before make sure your Docker Machine is stopped running:
docker-machine stop default # see PS below if docker machine isn't default
Option 1 - Use the VirtualBox interface
Open VirtualBox Manager
Select your Docker Machine VirtualBox image (e.g.: default)
Open Settings -> Network -> Advanced -> Port Forward
Add your app name, the desired host port (e.g.: 80) and your Guest port (e.g.: 3000)
Option 2 - Use the VirtualBox command line
Just run the following command with your own parameters:
VBoxManage modifyvm "dev" --natpf1 "myapp,tcp,,80,,3000"
Final considerations
Now you can start your Docker Machine running:
docker-machine start default
eval $(docker-machine env default)
Then just start your application Docker container and test it running http://localhost/.
P.S.: Your Docker Machine name may not be default, in this case change the name accordingly.
This can be achieved with ssh port forwarding:
ssh -L 0.0.0.0:80:localhost:3000 docker#$(docker-machine ip)
It will ask you for the docker user's password, which should be tcuser.
If your docker-machine instance is not named "default" then you'll have to specify its name in there like
ssh -L 0.0.0.0:80:localhost:3000 docker#$(docker-machine ip <name>)
If you are trying to run the bulletinboard example using the following ports
docker run --publish 8000:8080 --detach --name bb bulletinboard:1.0
On macOs you can open VirtualBox and then right-click on the machine
--> Settings --> Network --> Advanced --> Port Forwarding
If you add the following rule
Then you should be able to access the application using
> http://localhost:8100/
docker-machine uses VM underneath, usually VirtualBox.
You can find the IP address of that machine by:
docker-machine ip
You can access that IP directly:
docker run -p 8080:8080 apache --name hello
curl $(docker-machine ip):8080/index.html
Unfortunately that IP address is not permanent (could change after VBox restarts): port forwarding to localhost could make it permanent. You have stop VM and configure VM:
VBoxManage modifyvm "default" --natpf1 "myapp,tcp,,80,,3000"

How do I use docker from local to a remote machine?

I've noticed that boot2docker runs docker on a VM as a deamon on port 2375.
Then I use local Mac OS X 'docker' command and it executes all calls on VM.
These are the commands I use:
boot2docker start
export DOCKER_HOST=tcp://:2375
And then 'docker images' (for example) is running on VM.
How can I do the same with a physical machine rather then VM?
boot2docker is meant to be for dev purpose. It will spawn a VM. For bare metal, simply install docker on the host and start the docker daemon with docker -d -H tcp://0.0.0.0:4243.
WARNING: This is very dangerous. Anyone will have root access to your host. In order to secure this, you should change 0.0.0.0 to 127.0.0.1 and either use a SSH tunnel or a nginx/apache frontend with authentification.
On you mac, then just export DOCKER_HOST=tcp://<host ip>:4243

Resources