Boot2Docker: Connect to container over LAN

前端 未结 2 897
甜味超标
甜味超标 2021-02-06 15:25

I\'m using Boot2Docker 1.3.0 on my Mac and I\'m pretty happy so far using it. But now I\'d like to connect to a http container (exposes port 8080) not from my local machine but

2条回答
  •  悲哀的现实
    2021-02-06 16:01

    On your Mac, determine the IP address that it uses on your local LAN:

    $ ifconfig | grep 192
        inet 192.168.1.21 netmask 0xffffff00 broadcast 192.168.1.255
        inet 192.168.59.3 netmask 0xffffff00 broadcast 192.168.59.255
    

    Then port forward:

    $ boot2docker ssh -vnNTL 192.168.1.21:8080:localhost:8080
    

    Now, requests that come into your Mac on port 8080 will get forwarded to the boot2docker Linux VM on port 8080. The docker server will then forward from the exposed port (VM port 8080) to the port your container is using for httpd (probably 80).

    Note that "localhost" above is from the point of view of the Linux VM, not the Mac, because that is the host you are ssh'ing into.

提交回复
热议问题