I've just started using Docker and wanted to set up a simple nodejs container. I downloaded Docker Toolbox for Windows, followed some tutorials and was able to get it up and running. Since then, for some reason it has stopped working. Here's what I have so far:
Dockerfile
FROM node:7.8.0
WORKDIR /usr/src/app
COPY . .
RUN npm install --quiet --no-bin-links
RUN npm install --quiet -g nodemon@1.11.0
EXPOSE 8080
CMD ["node", "server/server.js"]
package.json
{
"name": "docker",
"version": "1.0.0",
"description": "Node.js on Docker",
"main": "server/server.js"
}
server/server.js
'use strict';
var http = require("http");
const PORT = 8080;
http.createServer(function (request, response) {
// Send the HTTP header
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(PORT, "0.0.0.0");
console.log('Running on port: ' + PORT);
Start command
docker run -d -p 8080:8080 --name backend -v $PWD/server:/usr/src/app/server/ my_node_image nodemon --legacy-watch server/server.js
Like I said above, this was working a few days ago. The server runs currently, but I cannot access it from my main computer via localhost:8080 as I did before.
via Jase Pellerin
No comments:
Post a Comment