简体   繁体   English

从容器外部访问 dockerized 节点应用程序时出现问题

[英]Problem accessing dockerized node application from outside of container

i have been trying to dockerize an angular project, using Docker Desktop for windows, with linux containers, and Hyper-V.我一直在尝试使用 windows 的 Docker 桌面和 ZE206A、0CC4E97670EE89CCEZ5 容器来对接 angular 项目。

Here is my dockerfile:这是我的 dockerfile:

FROM node:alpine

WORKDIR /var/app

EXPOSE 4200

COPY package*.json ./
COPY proxy*.json ./

COPY . .
RUN npm install @angular/cli -g
#Custom dependencies
RUN npm config set registry http://maven.corp.com.br:8081/artifactory/api/npm/
RUN npm install

RUN npm run build:dev

ENTRYPOINT npm start

i build it and can run it just fine with:我构建它并可以很好地运行它:

docker build -t name .

docker run -p 4200:4200 name

The problem is, when i try to access https://localhost:4200 from my windows pc, i get ERR_CONNECTION_CLOSED.问题是,当我尝试从我的 windows 电脑访问https://localhost:4200时,我得到 ERR_CONNECTION_CLOSED。

However, if i go into the container cli, and use Links (the command line web browser https://i.imgur.com/jwhD9cm.gif ) to access the url, it works just fine, i'm just having issues trying to access it from my windows pc. However, if i go into the container cli, and use Links (the command line web browser https://i.imgur.com/jwhD9cm.gif ) to access the url, it works just fine, i'm just having issues trying从我的 windows 电脑访问它。

I tried using the host.docker.domain dns aswell but no success.我也尝试使用 host.docker.domain dns 但没有成功。

Any help will be greatly appreciated.任何帮助将不胜感激。

Thanks!谢谢!

Thank you very much @paltaa, all i had to do was change from "npm start" to a custom "ng serve" with the flag --host 0.0.0.0"非常感谢@paltaa,我所要做的就是从“npm start”更改为带有标志的自定义“ng serve”--host 0.0.0.0”

change ENTRYPOINT npm start toENTRYPOINT npm start更改为

ENTRYPOINT npm start -- --host 0.0.0.0 --disable-host-check

or update package.json或更新package.json

"start": "ng serve --host 0.0.0.0 --disable-host-check",

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为 dockerized Angular 应用程序配置 Nginx - Configure Nginx for dockerized Angular application 从外部访问 angular 组件中的 CSS - Accessing CSS in angular component from outside CORS 关于在 Azure 虚拟机之外的浏览器上访问 Web 应用程序的问题 - CORS ISSUES on Accessing Web Application on a Browser Outside Azure Virtual Machine 从 Angular 中的 NgRx 减速器访问数据时出现问题 - Problem accessing data from NgRx reducers in Angular 从出口 function 访问服务时出现问题 - Problem accessing service from export function 通过Jenkins部署dockerized Angular应用程序时遇到问题 - Trouble with deploying a dockerized Angular application through Jenkins Dockerized angular cli 应用程序热重载失败 - Dockerized angular cli application hot reload fails 如何将 Docker 容器内的 node_modules 表单同步到 node_modules 文件夹外? - How to sync node_modules form inside Docker container to outside node_modules folder? Laravel + Angular 从外部网络访问被 CORS 阻止 - Laravel + Angular accessing from outside network blocked by CORS 如何从 Angular Nginx 容器连接到节点 API docker 容器 - How to connect to Node API docker container from Angular Nginx container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM