我已经开始使用docker for dev,使用以下设置:
I've started using docker for dev, with the following setup:
- 主机 - ubuntu服务器。
- Docker容器 - webapp w / tomcat服务器(使用https)。
只要主机容器访问 - 一切正常 但是,我无法从远程机器(尽管仍在同一个网络中)访问该容器的webapp。
As far as host-container access goes - everything works fine. However, I can't manage to access the container's webapp from a remote machine (though still within the same network).
运行
docker port <container-id> 443输出符合预期,因此docker的端口绑定似乎很好。
output is as expected, so docker's port binding seems fine.
172.16.*.*:<random-port>任何想法?
谢谢!
推荐答案我想出了我错过了什么,所以这里是一个简单的流程,用于从远程访问docker容器webapps机器:
I figured out what I missed, so here's a simple flow for accessing docker containers webapps from remote machines:
步骤#1 :将物理主机端口(例如22,443,80,...)绑定到容器的虚拟端口。 可能的语法:
Step #1 : Bind physical host ports (e.g. 22, 443, 80, ...) to container's virtual ports. possible syntax:
docker run -p 127.0.0.1:443:3444 -d <docker-image-name>(请参阅 docker docs进行端口重定向与所有选项)
步骤#2 :将主机的物理端口重定向到容器分配的虚拟端口。可能的(linux)语法:
Step #2 : Redirect host's physical port to container's allocated virtual port. possible (linux) syntax:
iptables -t nat -A PREROUTING -i <host-interface-device> -p tcp --dport <host-physical-port> -j REDIRECT --to-port <container-virtual-port>这应该涵盖基本用例。
祝你好运!
更多推荐
在docker容器中远程访问webserver
发布评论