Ping Docker容器从网络中的另一台机器 [英] Ping Docker Container from another machine in the network

查看:373
本文介绍了Ping Docker容器从网络中的另一台机器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个docker容器,并尝试在容器的bash内ping了www.google.com,它的工作原理。另外我也尝试从主机上ping容器 - 它工作得很好。

I have created a docker container and tried pinging www.google.com within the bash of the container and it works. Also I tried pinging the container from the host - it works perfectly fine.

但是当我尝试从网络中的外部系统ping容器时,它给了我一个请求超时例外。

But when I try to ping the container from a external system in the network, it gives me a request timed out exception.

我计划在容器上安装tomcat webserver,并允许其他容器访问部署在服务器中的应用程序。请谅解一些帮助!

I am planning to install a tomcat webserver on a container and allow other containers to access the application deployed in the server. Would appreciate some help!

推荐答案

默认情况下,您无法从外部主机ping一个Docker容器(要做到这一点,你会有以确保Docker网桥-docker0-具有IP地址,并且您必须在其他主机上配置路由以将Docker主机用作网桥地址范围的网关。)

You cannot ping a Docker container from an external host by default (to do so, you would have to ensure that the Docker network bridge -docker0- has an IP Address, and you would have to configure routes on your other hosts to use you Docker host as a gateway for the bridge address range).

默认情况下,在Docker容器中运行的任何服务都不是已发布(Docker术语),无法从外部访问。您必须在运行容器时明确定义/允许您要发布的服务。

By default, any service running inside a Docker container is not "Published" (Docker terminology) and cannot be reached from outside. You have to explicitly define/allow the services you want to be published when you run your container.

例如,要发布容器的Tomcat应用程序(假设配置为监听端口 8080 )到主机端口 80 ,您将使用 -p 选项运行您的容器:

For example, to publish your container's Tomcat app (supposing it is configured to listen on port 8080) to port 80 on the host, you would run your container using the -p option :


    docker run -d -p 80:8080 my-tomcat-image:tag 

但是,如果您只想从同一主机上的其他容器访问Tomcat,则不需要配置任何内容。

But if you only want to access Tomcat from other containers on the same host, you don't need to configure anything.

这篇关于Ping Docker容器从网络中的另一台机器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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