Boot2Docker - 将webserver作为localhost访问 [英] Boot2Docker - Access webserver as localhost

查看:146
本文介绍了Boot2Docker - 将webserver作为localhost访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我可以使用boot2docker的私有IP地址访问网络服务器,这个IP地址是192.168 .59.103但是想访问webserver作为localhost即127.0.0.1。



以下是我的Docker容器设置



在Oracle VM上运行Boot2docker
暴露的端口:EXPOSE 80 443在Docker文件中



用于创建Docker文件的命令:

  docker run --net = host --name = webserver1 -v /home/data:/data/www/www.samplewebserber.com -v`password`:/ scripts -d folder / serverfolder /scripts/run.sh 


解决方案

如果要访问localhost到端口80和443您需要执行两个操作:


  1. 首先,创建容器时,必须具体指定端口映射。如果您运行 docker运行 -P 选项,在dockerfile的 EXPOSE 将暴露给Boot2Docker环境中的随机端口。如果你想要具体地映射,你必须运行:

      docker run \ 
    --net = host \
    --name = webserver1 \
    -v /home/data:/data/www/www.samplewebserber.com \
    -v`password`:/ scripts \
    -d -p 80:80 -p 443:443 \
    文件夹/ serverfolder \
    /scripts/run.sh


  2. 为了将Boot2Docker端口映射到您的主机环境,如Joe Niland链接建议,您必须使用SSH隧道进行端口转发:



    boot2docker ssh -L 80:localhost:80



    boot2docker ssh -L 443:localhost:443


您可以更改为如果你愿意,你可以使用端口映射。


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 address which is 192.168.59.103 but would like to access the webserver as localhost i.e 127.0.0.1.

Following is my Docker Container setup

Running Boot2docker on Oracle VM Exposed ports : "EXPOSE 80 443" in docker file

Command used to create Docker File :

docker run --net=host --name=webserver1 -v /home/data:/data/www/www.samplewebserber.com -v `password`:/scripts -d folder/serverfolder  /scripts/run.sh

解决方案

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.

这篇关于Boot2Docker - 将webserver作为localhost访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆