如何让 ng serve 在 VirtualBox Docker 设置上使用主机名

How to get ng serve to work with host name on a VirtualBox Docker set up

我的设置:

Windows 10 运行ning 虚拟框 Ubuntu 16.04 运行ning 一个 docker 容器 @angular/CLI: 1.1.3 节点:6.11.0 从中调用 ng serve 到 运行 一个 angular 4 应用程序

在我的 windows 机器主机文件中,我的主机名 local.angular 指向 Vbox 的 192.168.56.101 并且我的虚拟框网络设置是 'host-only adaptor'

当运行ning ng serve it states NG Live Development Server 正在侦听 localhost:4200,请在 http://localhost:4200

打开浏览器

但是在我的浏览器上 localhost:4200 无法访问 docker 的本地主机

我试过 ng serve --host 0.0.0.0 和其他解决方案,none 其中有效

通过添加 "host" 配置 angular.cli.json "default" 配置来实现此功能:“[ip 地址]” 其中 ip 地址是 'localhost' 的 docker容器是。

这通常是 127.0.0.1 但是 docker 容器的默认 'bridge' 网络的本地主机是 172.17.0.2 通过 docker 检查 [容器 ID] 命令或从容器 ifconfig(ubuntu 上的 apt-get net-tools)现在使用 ng serve 并在 172.17.0.2:4200 打开浏览器显示无效的主机头。添加标志 --disable-host-check like "ng server --disable-host-check" 显示页面