如何在docker中部署平均堆栈应用程序?
我在mongodb连接中有错误。所以堆栈Web应用程序没有响应。
以下是我的步骤:
sudo docker pull crissi/airlineinsurance
已验证图片
sudo docker images
运行mongodb容器
sudo docker run -d -p 27017:27017 --name airlineInsurance -d mongo
已验证它正在运行:
sudo docker ps -l
运行应用程序容器
sudo docker run -d -P crissi/airlineinsurance
已通过验证:
sudo docker ps -l
检查日志
sudo docker logs 8efba551fdc6
结果日志如下:
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server.js`
Server running at http://127.0.0.1:9000
Server running at https://127.0.0.1:9030
/app/node_modules/mongodb/lib/server.js:261
process.nextTick(function() { throw err; })
^
MongoError: failed to connect to server [localhost:27017] on first connect
at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:313:35)
at emitOne (events.js:96:13)
at Pool.emit (events.js:188:7)
at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:271:12)
at Connection.g (events.js:291:16)
at emitTwo (events.js:106:13)
at Connection.emit (events.js:191:7)
at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:165:49)
at Socket.g (events.js:291:16)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at emitErrorNT (net.js:1281:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
[nodemon] app crashed - waiting for file changes before starting...
我已将DockerFile包含在您的参考
中 # Tells the Docker which base image to start.
FROM node
# Adds files from the host file system into the Docker container.
ADD . /app
# Sets the current working directory for subsequent instructions
WORKDIR /app
RUN npm install
RUN npm install -g bower
RUN bower install --allow-root
RUN npm install -g nodemon
#expose a port to allow external access
EXPOSE 9030
# Start mean application
CMD ["nodemon", "server.js"]
答案 0 :(得分:1)
这取决于您如何定义Dockerfile 由于您的应用涉及多个流程(您的应用+ mongodb),因此您可以 use supervisor to launch both 。
使用supervisord.conf
之类的内容{@ 3}}:
[supervisord]
nodaemon=true
[program:mongod]
command=/usr/bin/mongod --smallfiles
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s.log
autorestart=true
[program:nodejs]
command=nodejs /opt/app/server/server.js
用您自己的应用程序替换nodejs命令。