Boot2Docker - 将webserver作为localhost访问 [英] Boot2Docker - Access webserver as 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您需要执行两个操作:
-
首先,创建容器时,必须具体指定端口映射。如果您运行
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
-
为了将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:
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'sEXPOSE
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
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屋!