cd /home/www
1.下载镜像
docker pull docker.io/node
2 vim Dockerfile
=================
#Dockerfile文件
FROM docker.io/node
# Create app directory
RUN mkdir -p /home/Service
WORKDIR /home/Service
# Bundle app source
COPY . /home/Service
RUN npm install
#启动报错加下面两行nodejs Cannot GET
RUN npm install connect
RUN npm install serve-static
EXPOSE 8123
3 vim package.json
===========
{
"name": "nodetest",
"version": "1.0.0",
"description": "Node.js on Docker",
"author": "boatman",
"main": "test.js",
"scripts": {
"start": "node test.js"
},
"dependencies": {
"express": "^4.13.3"
}
}
4 vim test.js
===========
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8123);
5 docker build -t node/test .
6 docker run -d -p 8123:8123 node/test
7 测试 curl 127.0.0.1:8123
========
查看容器日志docker container logs 40c4a5f98e10