Docker-来自本地网络上其他计算机的访问 [英] Docker - Access from other machines on local network

查看:65
本文介绍了Docker-来自本地网络上其他计算机的访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 docker 撰写文件,用于设置 apache 服务器.这样做的目的是为了在我的本地网络上进行开发.

I have a docker compose file that sets up an apache server. The purpose of this is for development on my local network.

一切正常,我可以在运行 docker 的PC上访问它.如果我输入localhost:80,则会得到示例 PHP 索引文件.

All is working great and I can access it on the PC I am running docker on. If I type localhost:80 I get the sample PHP index file.

我现在希望能够从本地网络上的其他计算机访问此文件.我一直在阅读文档,看来桥接网络是我应该关注的.

I am now wanting to be able to access this from other machines on my local network. I have been reading the docs and it looks like bridge networking is what I should be looking at.

我在这个假设中正确吗?

Am I correct in this assumption?

我还想将自签名证书添加到Apache服务器,以便可以在本地网络上使用 https ,因此要确保Bridge网络也允许这样做.

I am also wanting to add self signed certificates to the Apache server so I can use https over the local network so want to make sure Bridge networking will allow for that as well.

有人可以提供一些建议吗?

Can anyone offer some advice?

推荐答案

如果您不打算将容器拆分到多台主机上,则只需使用用户定义的桥接网络.您不必在 docker-compose 为您创建默认网络后就对其进行显式配置.您所需要做的就是定义tcp/udp端口,这些端口应该在网络外部可用并公开它们.

User-defined bridge network is all you need for that if you are not planning to split your containers onto several host machines. You don't have to configure it explicitly as soon as docker-compose create default network for you. All you need is to define tcp/udp ports which should be available outside network and expose them.

因此,您可以通过主机的机器ip地址/主机名看到所有公开的服务.

Thus you get all your exposed services visible with your host's machine ip address/host name.

默认情况下,Docker将公开的端口绑定到所有可用接口,但是如果您需要仅在特定接口上提供服务,请使用以下语法:

By default Docker binds exposed ports to all available interfaces, but if you need your services to be available only on particular ones, use following syntax:

ports:
  - "<interface_ip>:<host_port>:<container_port>"

这篇关于Docker-来自本地网络上其他计算机的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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