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

简介: ####0 node应用·盗梦空间 ![2014_08_17_02_25_00](http://img1.tbcdn.cn/L1/461/1/462fcbef2aa688216c90fb6edbe364cc69629528) ####1 docker的NodeJs工作目录 ``` /home/erichan/docker-room/ubuntu-node ``` ####2

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

目录
相关文章
|
9月前
|
存储 测试技术 数据安全/隐私保护
【Docker项目实战】使用Docker部署dufs文件服务器
【Docker项目实战】使用Docker部署dufs文件服务器
1108 17
【Docker项目实战】使用Docker部署dufs文件服务器
|
8月前
|
Ubuntu 网络安全 PHP
如何使用vscode的Docker插件管理ubuntu 拉取服务器的镜像以及创建容器
本测试镜像旨在记录使用vscode的Docker插件拉取病创建Dockerfile,以及拉取镜像。
|
9月前
|
弹性计算 关系型数据库 Nacos
低配阿里云 ECS 如何 docker 环境部署 NACOS : 单机版模式
NACOS 单机版 Docker 安装指南。使用指定端口和 custom.env 配置文件启动 Nacos 服务,适用于 2.X 版本,包含 gRPC 支持及 MySQL 数据源配置。 -e MODE=standalone \
711 5
|
10月前
|
Ubuntu 安全 数据安全/隐私保护
在Docker容器中部署GitLab服务器的步骤(面向Ubuntu 16.04)
现在,你已经成功地在Docker上部署了GitLab。这就是我们在星际中的壮举,轻松如同土豆一样简单!星际旅行结束,靠岸,打开舱门,迎接全新的代码时代。Prepare to code, astronaut!
618 12
|
12月前
|
关系型数据库 MySQL Linux
在Linux环境下备份Docker中的MySQL数据并传输到其他服务器以实现数据级别的容灾
以上就是在Linux环境下备份Docker中的MySQL数据并传输到其他服务器以实现数据级别的容灾的步骤。这个过程就像是一场接力赛,数据从MySQL数据库中接力棒一样传递到备份文件,再从备份文件传递到其他服务器,最后再传递回MySQL数据库。这样,即使在灾难发生时,我们也可以快速恢复数据,保证业务的正常运行。
516 28
|
资源调度 JavaScript 网络安全

热门文章

最新文章