Angular项目无法回答我的要求

时间:2019-11-21 15:28:43

标签: node.js angular docker npm

我在被dockerized的Angular项目中遇到了一个问题。

在容器启动期间,即使容器的CMD不是应用程序的启动,似乎已经使用了用于项目的4200端口。
实际上,我的docker看起来像:

FROM node:11.10.1

ARG major
ARG minor
ARG sourceCodeReference
ARG productNumber
ARG revision
ARG timestamp

LABEL major=$major
LABEL minor=$minor
LABEL sourceCodeReference=$sourceCodeReference
LABEL productNumber=$productNumber
LABEL revision=$revision
LABEL timestamp=$timestamp

RUN mkdir -p /usr/src/app/
WORKDIR /usr/src/app/


COPY . /usr/src/app/
RUN npm install 
RUN printf "deb http://archive.debian.org/debian/ jessie main\ndeb-src http://archive.debian.org/debian/ jessie main\ndeb http://security.debian.org jessie/updates main\ndeb-src http:/
/security.debian.org jessie/updates main" > /etc/apt/sources.list
RUN apt-get update && apt-get install -y supervisor

COPY supervisord.conf /etc/supervisor/
COPY dash.conf /etc/supervisor/conf.d/
RUN ln -s /usr/src/app/node_modules/@angular/cli/bin/ng /usr/sbin/ng

#CMD ["/usr/bin/supervisord", "-n"]
CMD ["sleep", "infinity"]

考虑到该问题,我使用另一个端口4201更改了项目的配置,但是当我尝试在运行的角度应用程序中进行导航(这次)时,我没有收到任何答案。

可能是什么问题?如何验证锁定应用程序没有问题?

从以下位置开始注销应用程序:(手动在端口4200上)

 10% building 4/4 modules 0 activeExpress server listening on port 4200      
events.js:173
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use 127.0.0.1:4200
    at Server.setupListenHandle [as _listen2] (net.js:1256:14)
    at listenInCluster (net.js:1304:12)
    at GetAddrInfoReqWrap.doListen [as callback] (net.js:1443:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:63:10)
Emitted 'error' event at:
    at emitErrorNT (net.js:1283:8)
    at processTicksAndRejections (internal/process/next_tick.js:76:17)
root@5abd5b6fa13d:/usr/src/app#  --prodps au^C
root@5abd5b6fa13d:/usr/src/app# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   4188   676 ?        Ss   15:13   0:00 sleep infinity
root         7  0.0  0.0  18252  3324 pts/0    Ss   15:13   0:00 bash
root        31  0.5  0.0      0     0 pts/0    Z    15:15   0:00 [node] <defunct
root        38  0.0  0.0  36636  2776 pts/0    R+   15:17   0:00 ps aux
root@5abd5b6fa13d:/usr/src/app# 

在启动已失效节点之前,该节点未运行,并且显然其他进程未使用4200:

相反,当我将端口更改为4201时,启动阶段看起来不错:(但是我仍然无法通过chrome加载我的角度项目)

** Angular Live Development Server is listening on localhost:4201, open your browser on https://localhost:4200/ **
 10% building 4/4 modules 0 activeExpress server listening on port 4201      
 40% building 145/145 modules 0 active                                           
MongoDb connected !!!

Date: 2019-11-21T13:35:39.337Z
Hash: ef9332be02eca07b14c4
Time: 147804ms
chunk {0} runtime.26209474bfa8dc87a77c.js, runtime.26209474bfa8dc87a77c.js.map (runtime) 1.46 kB [entry] [rendered]
chunk {1} es2015-polyfills.d4e1d1f26e719a5dba37.js, es2015-polyfills.d4e1d1f26e719a5dba37.js.map (es2015-polyfills) 56.6 kB [initial] [rendered]
chunk {2} main.6c559f8f936550d86d03.js, main.6c559f8f936550d86d03.js.map (main) 2.33 MB [initial] [rendered]
chunk {3} polyfills.e65198f4c10e2cae53b9.js, polyfills.e65198f4c10e2cae53b9.js.map (polyfills) 41.1 kB [initial] [rendered]
chunk {4} styles.421c2a405fa16d4f5f7f.css, styles.421c2a405fa16d4f5f7f.css.map (styles) 315 kB [initial] [rendered]
chunk {scripts} scripts.086b20530ca3f0670b5f.js, scripts.086b20530ca3f0670b5f.js.map (scripts) 1.04 MB [entry] [rendered]

WARNING in budgets, maximum exceeded for initial. Budget 2 MB was exceeded by 1.78 MB.
ℹ 「wdm」: Compiled with warnings.

我有点困惑。

      netstat -nltp
root@1df394cfdaed:/usr/src/app# netstat -nltp 
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:4200          0.0.0.0:*               LISTEN      335/myappl.cert 
tcp        0      0 127.0.0.11:42897        0.0.0.0:*               LISTEN      -               
tcp6       0      0 :::4201                 :::*                    LISTEN      335/myappl.cert 
tcp6       0      0 :::80                   :::*                    LISTEN      335/myappl.cert 

我应该在收听80时有服务吗?

docker ps
CONTAINER ID        IMAGE                                                          COMMAND                  CREATED             STATUS                   PORTS                                                                                      NAMES
1df394cfdaed        myapplication:13.0   "docker-entrypoint.s…"   18 minutes ago      Up 18 minutes            0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:3000->3000/tcp, 0.0.0.0:4201->4201/tcp   scripts_myappl_1

1 个答案:

答案 0 :(得分:0)

问题与ng服务器(4200)使用的默认端口有关。
我的代码(server.js)中使用了相同的端口

// Node express server setup. 
var app = express();
app.set('port', 4200);

通过将端口更改为443(ng serve --port 443)并恢复4200的使用,即可正常工作。