ubuntu 18.04 docker nodejs镜像

  1. 新建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);
  1. 新建package.json
npm init -y
  1. package.json文件中定义命令 "start": "node index.js"
  2. 新建Dockerfile
from hub.c.163.com/library/node

MAINTAINER cuichen [email protected]

RUN mkdir -p /home/www/cuic
WORKDIR /home/www/cuic

COPY . /home/www/cuic

RUN npm install

EXPOSE 8888

CMD ["npm", "run", "start"]
  1. 创建镜像
docker build -t cuic-node:latest .
docker images
  1. 运行镜像
docker run -d -p 88:8888 cuic-node
docker ps
  1. 访问localhost:88

你可能感兴趣的:(ubuntu 18.04 docker nodejs镜像)