Boot2Docker - Access webserver as localhost

后端 未结 2 1763
遇见更好的自我
遇见更好的自我 2021-01-02 11:54

Created a apache webserver as Docker container but want to access it on windows os browser as localhost.

I can access the webserver with boot2docker private ip addre

2条回答
  •  醉梦人生
    2021-01-02 12:27

    If you want to access localhost to ports 80 and 443 you need to perform two actions:

    1. First, when you create your container, you must specify the port mapping specifically. If you run docker run with -P option, the ports set in dockerfile's EXPOSE will be expose to random ports in the Boot2Docker environment. If you want to map it specifically you must run:

      docker run \
        --net=host \
        --name=webserver1 \
        -v /home/data:/data/www/www.samplewebserber.com \
        -v `password`:/scripts \
        -d -p 80:80 -p 443:443 \
        folder/serverfolder  \
        /scripts/run.sh
      
    2. And in order to map Boot2Docker port to your host environment, as Joe Niland link suggested, you must do a port forwarding using SSH tunneling:

      boot2docker ssh -L 80:localhost:80

      boot2docker ssh -L 443:localhost:443

    You can change to port mappings if you wish.

提交回复
热议问题