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

标签 angularjs windows docker virtualbox angular-cli

我的设置:

Windows 10 运行虚拟框,Ubuntu 16.04 运行带有@angular/CLI 的 docker 容器:1.1.3 节点:6.11.0 从中调用 ng serve 来运行 angular 4 应用程序

在我的 Windows 机器主机文件上,我的主机名 local.angular 指向 Vbox 的 192.168.56.101,我的虚拟框网络设置是“仅主机适配器”

当运行 ng serve 时它声明 NG Live Development Server 正在监听 localhost:4200,在 http://localhost:4200 上打开浏览器

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

我试过 ng serve --host 0.0.0.0 和其他解决方案,都没有用

最佳答案

通过添加 "host": "[ip address]"配置 angular.cli.json "default"配置来实现这个工作,其中 ip 地址是你的 docker 容器的 'localhost'。

这通常是 127.0.0.1,但是通过 docker inspect [container-id] 命令或从容器 ifconfig(apt-get net-tools在 ubuntu 上)现在使用 ng serve 并在 172.17.0.2:4200 打开浏览器显示无效的主机头。添加标志 --disable-host-check 就像“ng server --disable-host-check”显示页面

关于angularjs - 如何让 ng serve 在 VirtualBox Docker 设置上使用主机名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44719061/

相关文章:

angularjs - 未应用 Angular 布局/弹性

javascript - 带有 angularjs 的有效输入掩码(ui-mask)

node.js - ECONNREFUSED for Postgres on nodeJS with dockers

angularjs - 如何在不引发错误的情况下检查模块的存在?

javascript - Bootstrap 时间选择器在增加或减少小时和分钟时得到 NaN

windows - 带双引号的批处理文件多行命令

c# - UWP x :Bind with time

windows - 在 Windows 中,除了可移植性之外,我应该使用 CreateFile 还是 fopen?

apache - 无法使用 docker 自动启动 apache

docker - 从正在运行的 keycloak docker 容器导出领域失败