0

我部署一個節點應用AWS EB,這裏是我的Dockerfilesupervisord放棄的NodeJS進入致命狀態

FROM ubuntu:14.04 

RUN rm /bin/sh && ln -s /bin/bash /bin/sh 

# Install base packages 
ENV DEBIAN_FRONTEND noninteractive 
RUN apt-get update && apt-get install -y \ 
    zsh \ 
    vim \ 
    git \ 
    curl \ 
    build-essential \ 
    nodejs \ 
    npm \ 
    supervisor 

RUN update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10 

RUN mkdir -p /var/run/sshd /var/log/supervisor 

COPY build/supervisord.conf /etc/supervisor/conf.d/supervisord.conf 

RUN mkdir -p /app 
ADD api/ /app 

RUN cd /app && npm install 

WORKDIR /app 

EXPOSE 8090 

CMD ["/usr/bin/supervisord"] 

這裏是我的supervisord.conf

[supervisord] 
nodaemon=true 

[program:nodejs] 
directory=/app 
command=node server.js web 
autorestart = true 
stdout_logfile=/var/log/%(program_name)s.log 
stderr_logfile=/var/log/%(program_name)s.log 

這裏是我的stdouterr.log

/usr/lib/python2.7/dist-packages/supervisor/options.py:295: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security. 
'Supervisord is running as root and it is searching ' 
2016-04-08 16:48:37,892 CRIT Supervisor running as root (no user in config file) 
2016-04-08 16:48:37,892 WARN Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing 
2016-04-08 16:48:37,909 INFO RPC interface 'supervisor' initialized 
2016-04-08 16:48:37,909 CRIT Server 'unix_http_server' running without any HTTP authentication checking 
2016-04-08 16:48:37,910 INFO supervisord started with pid 1 
2016-04-08 16:48:38,912 INFO spawned: 'nodejs' with pid 11 
2016-04-08 16:48:39,332 INFO exited: nodejs (exit status 8; not expected) 
2016-04-08 16:48:40,334 INFO spawned: 'nodejs' with pid 13 
2016-04-08 16:48:40,732 INFO exited: nodejs (exit status 8; not expected) 
2016-04-08 16:48:42,736 INFO spawned: 'nodejs' with pid 15 
2016-04-08 16:48:43,414 INFO exited: nodejs (exit status 8; not expected) 
2016-04-08 16:48:46,419 INFO spawned: 'nodejs' with pid 17 
2016-04-08 16:48:47,288 INFO exited: nodejs (exit status 8; not expected) 
2016-04-08 16:48:48,289 INFO gave up: nodejs entered FATAL state, too many start retries too quickly 

任何建議在這一點上是有幫助的。

+0

是您的節點的應用程序崩潰?改爲嘗試一個最小節點應用程序。也嘗試從節點打印到stdout來調試裏面出了什麼問題。 –

+0

你說得對,@AssafLavie我的節點應用程序崩潰了,因爲我的節點和npm版本沒有設置爲正確的。 – gmaniac

回答

0

作爲@AssafLavie在評論中提到節點應用程序崩潰。它崩潰的原因是因爲我必須將nodenpm版本設置爲我的package.json文件中的指定版本。

Dockerfile現在看起來

FROM ubuntu:14.04 

RUN rm /bin/sh && ln -s /bin/bash /bin/sh 

# Install base packages 
ENV DEBIAN_FRONTEND noninteractive 
RUN apt-get update && apt-get install -y \ 
    zsh \ 
    vim \ 
    git \ 
    curl \ 
    build-essential \ 
    nodejs \ 
    npm \ 
    supervisor 

RUN update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10 

# Added the following 5 lines 

RUN npm install -g n 

RUN n 5.0.0 

RUN rm /usr/bin/node 
RUN ln -s /usr/local/bin/node /usr/bin/node 

RUN npm install [email protected] -g 

# End of the added lines to specify node and npm versions 

RUN mkdir -p /var/run/sshd /var/log/supervisor 

COPY build/supervisord.conf /etc/supervisor/conf.d/supervisord.conf 

RUN mkdir -p /app 
ADD api/ /app 

RUN cd /app && npm install 

WORKDIR /app 

EXPOSE 8090 

CMD ["/usr/bin/supervisord"]