Docker应用程序处于退出(0)状态(Docker app in Exited (0) status)
我正在尝试在Docker容器中运行一个小服务器应用程序
index.js
var server_port = 3111 , http = require('http') , mosca = require('mosca') , dispatch = require('dispatch') , httpServ = http.createServer( dispatch({ '/': function(req, res, next){ console.log('in route'); } }) ); httpServ.listen(server_port, function() { console.log("listening on", server_port); });
的package.json
{ "dependencies": { "dispatch": "^1.0.0" }, "description": "", "engines": { "node": ">= 0.10.4" }, "main": "index.js", "name": "SimpleServer", "version": "0.0.1" }
Dockerfile
FROM centos:centos6 # Enable EPEL for Node.js RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm # Install Node.js and npm RUN yum install -y npm # Install nodemon RUN npm install -g nodemon # Bundle app source COPY . /src # Install app dependencies RUN cd /src; npm install # Expose port EXPOSE 3111 # Run app using nodemon RUN echo "***" && pwd && echo "***" CMD ["nodemon", "/src/index.js"]
在Docker终端中,在SimpleServer工作目录中,命令
$ docker build -t test_simple .
Successfully built 43c8806574f4
。 到目前为止在容器中运行映像的任何尝试,例如$ docker run -p 3111 test_simple
导致代码退出,服务器没有运行。$ docker run -p 3111 test_simple 19 Aug 07:22:56 - [nodemon] v1.4.1 19 Aug 07:22:56 - [nodemon] to restart at any time, enter `rs` 19 Aug 07:22:56 - [nodemon] watching: *.* 19 Aug 07:22:56 - [nodemon] starting `node /src/index.js` Master: 16 19 Aug 07:22:57 - [nodemon] clean exit - waiting for changes before restart $ docker run -d -P test_simple node /src/index.js a0a56ec5c13161bc37b523be0e32edec0a43ca82e7db88ddb2a91688f745b24b $ docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a0a56ec5c131 test_simple "node /src/index.js" 6 seconds ago Exited (0) 6 seconds ago jolly_bohr
我不知道发生了什么,以及服务器退出的原因。 任何反馈都表示赞赏。 谢谢。
I'm trying to run a little server application in a Docker container
index.js
var server_port = 3111 , http = require('http') , mosca = require('mosca') , dispatch = require('dispatch') , httpServ = http.createServer( dispatch({ '/': function(req, res, next){ console.log('in route'); } }) ); httpServ.listen(server_port, function() { console.log("listening on", server_port); });
package.json
{ "dependencies": { "dispatch": "^1.0.0" }, "description": "", "engines": { "node": ">= 0.10.4" }, "main": "index.js", "name": "SimpleServer", "version": "0.0.1" }
Dockerfile
FROM centos:centos6 # Enable EPEL for Node.js RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm # Install Node.js and npm RUN yum install -y npm # Install nodemon RUN npm install -g nodemon # Bundle app source COPY . /src # Install app dependencies RUN cd /src; npm install # Expose port EXPOSE 3111 # Run app using nodemon RUN echo "***" && pwd && echo "***" CMD ["nodemon", "/src/index.js"]
In the Docker Terminal, and within the SimpleServer working directory, the command
$ docker build -t test_simple .
resulted inSuccessfully built 43c8806574f4
. Any attempt so far to run the image in a container, such as$ docker run -p 3111 test_simple
consistently results in the code exiting, and the server not running.$ docker run -p 3111 test_simple 19 Aug 07:22:56 - [nodemon] v1.4.1 19 Aug 07:22:56 - [nodemon] to restart at any time, enter `rs` 19 Aug 07:22:56 - [nodemon] watching: *.* 19 Aug 07:22:56 - [nodemon] starting `node /src/index.js` Master: 16 19 Aug 07:22:57 - [nodemon] clean exit - waiting for changes before restart $ docker run -d -P test_simple node /src/index.js a0a56ec5c13161bc37b523be0e32edec0a43ca82e7db88ddb2a91688f745b24b $ docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a0a56ec5c131 test_simple "node /src/index.js" 6 seconds ago Exited (0) 6 seconds ago jolly_bohr
I cannot tell what's going on, and why the server is exiting. Any feedback is appreciated. Thanks.
原文:https://stackoverflow.com/questions/32089086