Mac uses Docker-machine to access Docker publish port

Source: Internet
Author: User
Tags jboss docker run

Step 1, Export the port in your container (Docker-machine or Boot2docker)

First of all, make sure that you publish the image of the port already run. Let's say you're the image that was build up through Dockerfile. Note Add the following paragraph to the image:

Expose 80

Let's say you need to make the other port available, just change the 80.

Expose this command means that Docker image publishes a port.

Then you need to specify a port to bind the image based on this container:

Docker Rum-p 80:80-d Your_image

The meaning of the-p option is to bind the 80port to the 80port of the host ("host" here means Docker-machine or boot2docker container)

Let's say you don't want to go through http://localhost:80 on your Mac or Windows, and it's over.

You can access it through your docker-machine or boot2docker IP.

$docker-machine IP machine_name192.168.99.100

Here I will be able to access my published image through http://192.168.99.100:80.


Step 2, Configure VirtualBox

As everyone knows, docker-machine and Boot2docker cannot be executed directly under Mac or Windows, it must be attached to a VM, where the VM is VirtualBox. How to get us to the app advertised in Docker, we need to open VirtualBox port forwarding.

Execute the following command to forward the 80port of the osx/windows 80port to boot2docker/docker-machine vm via SSH:

$ boot2docker Ssh-vnntl *:80:localhost:80

Or you can set the VirtualBox's number of parameters for port forwarding:

$ vboxmanage MODIFYVM "BOOT2DOCKER-VM"--natpf1 "tcp-port8000,tcp,,80,,80";

Assuming your VM is still in running, you need to execute the following command:

$ vboxmanage CONTROLVM "BOOT2DOCKER-VM" natpf1 "tcp-port8000,tcp,,80,,80";

Now you can go through the localhost:80.


Assuming you have very many containers to advertise the same port, you need to use Docker's dynamic forwarding

For example, running 3 nginx containers:

Container-1:49153 (i.e Docker run-p 49,153:80 ...) Container-2:49154 (i.e Docker run-p 49,154:80 ...) Container-3:49155 (i.e Docker run-p 49,155:80 ...)

Use the Vboxmanage MODIFYVM command to forward 49XXXport.

Such a method can be very easy to do at the same time forward.

# VM must is powered offfor I in {49000..49900}; Do vboxmanage modifyvm "BOOT2DOCKER-VM"--natpf1 "tcp-port$i,tcp,, $i,, $i"; Vboxmanage modifyvm "BOOT2DOCKER-VM"--natpf1 "udp-port$i,udp,, $i,, $i";d one

If you need to delete the published port, you can do this:
# VM must is powered offfor I in {49000..49900}; Do vboxmanage modifyvm "BOOT2DOCKER-VM"--natpf1 delete "tcp-port$i"; Vboxmanage modifyvm "BOOT2DOCKER-VM"--natpf1 Delete "udp-port$i";d One


another release of JBoss will be the discovery of external access, which is due to the fact that the JBoss application is only valid for localhost, assuming that you want to ask outside. The start command must be appended with the
<strong><span style= "FONT-SIZE:24PX;" >-b 0.0.0.0</span></strong>

This binds the entire IP, otherwise only the machine can be interviewed.



This article: https://github.com/boot2docker/boot2docker/blob/master/doc/WORKAROUNDS.md
https://github.com/boot2docker/boot2docker/issues/976
https://fogstack.wordpress.com/2014/02/09/docker-on-osx-port-forwarding/



    Mac uses Docker-machine to access Docker publish port

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.