- 新建index.js文件
var http = require("http");
http.createServer(function(req,res){
res.writeHead(200,{"Content-type":"text/html"});
res.write("Hello NodeJs");
res.end();
}).listen(8888);
- 新建package.json
npm init -y
- package.json文件中定义命令 "start": "node index.js"
- 新建Dockerfile
from hub.c.163.com/library/node
MAINTAINER cuichen cancer_1942913930@163.com
RUN mkdir -p /home/www/cuic
WORKDIR /home/www/cuic
COPY . /home/www/cuic
RUN npm install
EXPOSE 8888
CMD ["npm", "run", "start"]
- 创建镜像
docker build -t cuic-node:latest .
docker images
- 运行镜像
docker run -d -p 88:8888 cuic-node
docker ps
- 访问localhost:88
网友评论