为容器分配域名 [英] Assign domain name to the container

查看:181
本文介绍了为容器分配域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在容器启动时为其分配域名的方法。例如,我想启动一个Web服务器容器,并且能够通过域名访问网页。有没有办法做到这一点?

I am looking for a way to assign a domain name to the container when it is started. For example, I want to start a web server container, and to be able to access web pages via domain name. Is there an easy way to do this ?

推荐答案

对于我所知道的, Docker 不提供此功能开箱即用。但是这里肯定有几个解决方法。实际上,您需要在主机上部署DNS,以区分容器并在动态IP中解析其域名。所以你可以尝试:

For all I know, Docker doesn't provide this feature out of the box. But surely there are several workarounds here. In fact you need to deploy a DNS on your host that will distinguish the containers and resolve their domain names in dynamical IPs. So you could give a try to:


  1. 部署一些Docker感知的DNS解决方案(我建议你使用 SkyDNSv1 / SkyDock );

  2. 将您的主机配置为使用此DNS(默认情况下为 SkyDNS 使容器通过名称相互认识,但主机不知道);

  3. 以显式的<$ c $运行您的容器c> - hostname (您可能会使用scheme container_name.image_name.dev.skydns.local )。

  1. Deploy some of Docker-aware DNS solutions (I suggest you to use SkyDNSv1/SkyDock);
  2. Configure your host to work with this DNS (by default SkyDNS makes the containers know each other by name, but the host is not aware of it);
  3. Run your containers with explicit --hostname (you will probably use scheme container_name.image_name.dev.skydns.local).

您可以跳过步骤2,并在容器内运行浏览器:它将通过主机名发现Web应用程序容器。

You can skip step #2 and run your browser inside container too: it will discover the web application container by hostname.

这篇关于为容器分配域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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