[Docker系列·3] 搭建基于Docker的NodeJS服务器

0 node应用·盗梦空间

2014_08_17_02_25_00

1 docker的NodeJs工作目录
/home/erichan/docker-room/ubuntu-node
2 docker的Dockerfile

[erichan@mars-centos7 ubuntu-node]$ nano Dockerfile

# Version: 0.0.1
FROM feuyeux/ubuntu-base
MAINTAINER Eric Han "feuyeux@gmail.com"
RUN apt-get -yq install nodejs
RUN apt-get -yq install npm
COPY index.js ./index.js
COPY package.json ./package.json
RUN npm install
EXPOSE 8080
CMD ["nodejs","./index.js"]
3 nodejs工程

[erichan@mars-centos7 ubuntu-node]$ nano package.json

{
  "name": "ubuntu-node",
  "private": true,
  "version": "0.0.5",
  "description": "pi arcas app on CentOS using docker",
  "author": {
    "name":"Eric Han",
    "email":"feuyeux@gmail.com"
  },
  "dependencies": {
      "tracer": "0.7.1"
    },
    "devDependencies": {
        "mocha": "1.21.3",
        "should": "4.0.4",
        "expect": "0.1.1",
        "nodeunit": "0.9.0",
        "date-format-lite": "0.5.0",
        "express":"4.8.4"
    }
}

[erichan@mars-centos7 ubuntu-node]$ nano index.js

var express = require('express');
var config = {
  root: "/tmp",
  format: "{{timestamp}} {{message}}",
  dateformat: "yyyy-mm-dd HH:MM:ss.L"
};

var log = require('tracer').dailyfile(config); 
var PORT = 8080;

var app = express();
app.get('/', function (req, res) {
  log.info(req);
  res.send("Qui, c'est la pi-arcas!\n");
});
app.listen(PORT);
console.log('Running on http://localhost:' + PORT);
4 制作镜像
d build -t feuyeux/ubuntu-node .
5 验证镜像
d images

screenshot

6 运行node
[erichan@mars-centos7 ubuntu-node]$ d run -p 49160:8080 -d feuyeux/ubuntu-node
7 验证NodeJs

查询进程

[erichan@mars-centos7 ubuntu-node]$ d ps -l
CONTAINER ID        IMAGE                        COMMAND             CREATED             STATUS              PORTS                             NAMES
658829faa174        feuyeux/ubuntu-node:latest   nodejs ./index.js   4 seconds ago       Up 4 seconds        22/tcp, 0.0.0.0:49160->8080/tcp   focused_davinci     

cURL测试

[erichan@mars-centos7 ubuntu-node]$ curl -i localhost:49160
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 24
ETag: W/"18-1035073832"
Date: Sat, 16 Aug 2014 18:06:11 GMT
Connection: keep-alive

Qui, c'est la pi-arcas!

2014_08_17_02_30_40

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值