【问题标题】:Deploy angular application in Openshift 4在 Openshift 4 中部署 Angular 应用程序
【发布时间】:2021-09-09 00:47:42
【问题描述】:

我正在尝试在 openshift 中部署 Angular 应用程序。我在项目中只有一个带有 dockerfile 的 Angular 项目,它执行 ng build --prod 和 npm start 来启动应用程序。问题是我看到它在 localhost 内部而不是 openshift 主机中运行。因此,我在点击 openshift url 时在浏览器中收到“应用程序不可用”。请支持纠正它。

下面是 Pod 的日志

exmaple-ui@0.0.0 start /ng-app
> ng serve --host 0.0.0.0 --port 4200

WARNING: This is a simple server for use in testing or debugging Angular applications
locally. It hasn't been reviewed for security issues.

Binding this server to an open connection can result in compromising your application or
computer. Using a different host than the one passed to the "--host" flag might result in
websocket connection issues. You might need to use "--disableHostCheck" if that's the
case.
** Angular Live Development Server is listening on 0.0.0.0:4200, open your browser on http://localhost:4200/ **

Date: 2020-02-26T06:08:37.782Z
Hash: dc7eff7d77f7a5fbef4e
Time: 81197ms
chunk {es2015-polyfills} es2015-polyfills.js, es2015-polyfills.js.map (es2015-polyfills) 285 kB [initial] [rendered]
chunk {main} main.js, main.js.map (main) 97.8 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 236 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.08 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 3.61 MB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 7.4 MB [initial] [rendered]
[34mℹ[39m [90m「wdm」[39m: Compiled successfully.

【问题讨论】:

  • 你能粘贴你的docker文件,服务yml,路由yml吗?

标签: openshift


【解决方案1】:

我会建议..

  1. 在本地或任何 CI(Jenkins 等)上构建 Angular 应用程序,ng build --prod
  2. 使用 nginx 镜像部署和放置静态内容,nginx config。

2.1 Docker 镜像

FROM nginx:1.13.3-alpine
## Copy our nginx config
COPY nginx/ /etc/nginx/conf.d/
## Remove default nginx website
RUN rm -rf /usr/share/nginx/html/* && chmod -R 777 /var/log/nginx /var/cache/nginx/ && chmod -R 777 /etc/nginx/* && chmod -R 777 /var/run/ && chmod -R 777 /usr/share/nginx/
## copy over the artifacts in dist folder to default nginx public folder
COPY dist/MyApp /usr/share/nginx/html
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]

【讨论】:

  • 我没有超级用户权限我猜是因为我在尝试时得到“操作不允许”。
猜你喜欢
  • 2017-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多