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?
Map TCP port 80 in the container to port 8080 on the Docker host for connections to host IP 192.168.1.100. Map UDP port 80 in the container to port 8080 on the Docker host. Map TCP port 80 in the container to TCP port 8080 on the Docker host, and map UDP port 80 in the container to UDP port 8080 on the Docker host.
You can expose a port through your Dockerfile or use --expose and then publish it with the -P flag. This will bind the exposed port to your Docker host on a random port (verified by running docker container ls ). You can expose a port through your Dockerfile or use --expose and then publish it with the -p 80:80 flag.
To publish a port for our container, we'll use the --publish flag ( -p for short) on the docker run command. The format of the --publish command is [host port]:[container port] . So, if we wanted to expose port 8000 inside the container to port 8080 outside the container, we would pass 8080:8000 to the --publish flag.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With