在docker容器中远程访问webserver

编程入门 行业动态 更新时间:2024-10-24 01:53:24
本文介绍了在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

本文发布于:2023-10-27 11:34:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533238.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:容器   远程访问   docker   webserver

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!