简体   繁体   English

使用主管在Docker中运行Node和Nginx

[英]Running node and nginx in docker with supervisor

I'm trying to setup node and nginx inside my docker container, using supervisor to start and monitor both processes. 我试图在docker容器中设置node和nginx,使用超级用户启动和监视两个进程。 I have a supervisor conf file that starts nginx and node. 我有一个启动nginx和node的supervisor conf文件。

The problem is that when I try to use supervisorctl to access the services they are not found. 问题是,当我尝试使用supervisorctl访问服务时,找不到它们。 So I think I must be doing something wrong. 所以我想我一定做错了。

supervisor.conf supervisor.conf

[supervisord]
nodaemon=true

[program:nodeServer]
directory=/app/backend
command=/nodejs/bin/node app.js 
autostart=true
autorestart=unexpected
user=www-app
startsecs=10
stdout_logfile=/var/log/repositive.io/supervisor.log
redirect_stderr=true

[program:nginx]
command=/usr/sbin/nginx
stdout_events_enabled=true
stderr_events_enabled=true

dockerfile dockerfile

FROM google/debian:wheezy

# update and install nginx and supervisor
RUN apt-get update -y && \
    apt-get install --no-install-recommends -y -q \
    curl python build-essential git ca-certificates nginx-extras supervisor

# install node
RUN mkdir /nodejs && \
    curl http://nodejs.org/dist/v0.10.32/node-v0.10.32-linux-x64.tar.gz | \
    tar xvzf - -C /nodejs --strip-components=1

ENV PATH $PATH:/nodejs/bin

# setup db
RUN apt-get install -y postgresql

USER postgres
RUN /etc/init.d/postgresql start && \
    createuser repositive -S -D -R && \
    createdb --owner=repositive --port=5432 repositive && \
    createdb --owner=repositive --port=5432 repositive-testing

# init app
USER root
RUN mkdir -p /var/www/repositive.io
RUN mkdir -p /var/log/repositive.io
RUN chown -R www-data:www-data /var/www/repositive.io

WORKDIR /app
ONBUILD ADD nginx.conf /etc/nginx/sites-available/default
ONBUILD ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
ONBUILD ADD ../ /app
ONBUILD RUN npm install

ENV NODE_ENV production

EXPOSE 80
CMD ["/usr/bin/supervisord"]

Now I try to access one of the services by building the image than running running it in interactive mode: 现在,我尝试通过构建映像来访问其中一项服务,而不是以交互方式运行它:

sudo docker run -t -i timrich/api.repositive.io:V0.0.1 /bin/bash
root@b16b20f8f1b4:/app# /usr/bin/supervisord
root@b16b20f8f1b4:/app# supervisorctl status nginx
No such process nginx

But none of the supervisor jobs are found 但是找不到主管的工作

When you run your Docker container with docker run ... [command] you overwrite the default command which is specified in your dockerfile (supervisord) see here . 当您使用docker run ... [命令]运行Docker容器时,您将覆盖dockerfile(supervisord)中指定的默认命令, 请参见此处 Try starting it without the command option, in your case "/bin/bash". 尝试在不使用命令选项的情况下启动它,在您的情况下为“ / bin / bash”。 This means in your case you stared the bash instead of supervisord, which means that no processes from supervisord are started. 这意味着在您的情况下,您盯着猛击而不是监督者,这意味着不会启动监督者的流程。

If you want to check if everything works you can use docker logs or docker exec . 如果要检查一切是否正常,可以使用docker日志docker exec

您是否考虑过在单独的容器中运行这两项服务?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM