aug2uag
aug2uag

Reputation: 3435

Docker app in Exited (0) status

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 in Successfully 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.

Upvotes: 3

Views: 2787

Answers (1)

Vincent De Smet
Vincent De Smet

Reputation: 4979

You can use docker run --rm -it test_simple bash to get a shell into the container, then try to run nodemon /src/index.js manually and find out what may go wrong there, as well as run node directly instead of nodemon while debugging this issue.

Also, it may be better to base off the official node image

Upvotes: 3

Related Questions