在docker容器中远程访问webserver [英] Remote access to webserver in docker container

查看:200
本文介绍了在docker容器中远程访问webserver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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