Docker 生成Node.js web app(含端口映射)
1.新建目录src,并进入src目录
[xiejdm@localhost Documents]$ mkdir src
[xiejdm@localhost Documents]$ cd src/
2.创建package.json和index.js文件,文件内容如下:
package.json
[xiejdm@localhost Documents]$ mkdir src
[xiejdm@localhost Documents]$ cd src/
[xiejdm@localhost src]$ cat package.json
{
"name": "docker-centos-hello",
"private": true,
"version": "0.0.1",
"description": "Node.js Hello world app on CentOS using docker",
"author": "Gideon xie <xiejdml@gmail.com>",
"dependencies": {
"express": "3.2.4"
}
}
index.js
[xiejdm@localhost src]$ cat index.js
var express = require('express'); // Constants
var PORT = 8080; // App
var app = express();
app.get('/', function (req, res) {
res.send('Hello world\n');
}); app.listen(PORT);
3.创建Dockfile
[xiejdm@localhost src]$ cat Dockerfile
FROM centos:centos7 # Enable EPEL for Node.js
RUN yum install -y epel-release
# Install Node.js and npm
RUN yum install -y npm # Bundle app source
COPY . /src
# Install app dependencies
RUN cd /src; npm install EXPOSE
CMD ["node", "/src/index.js"]
[xiejdm@localhost src]$
4.使用docker build构建生成镜像
[xiejdm@localhost src]$ docker build -t gideon/centos-node-hello .
Sending build context to Docker daemon 4.096 kB
Sending build context to Docker daemon
Step : FROM centos:centos7
---> 7322fbe74aa5
Step : RUN yum install -y epel-release
---> Running in 858c0e3e9a22
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirrors.yun-idc.com
* extras: mirrors.yun-idc.com
* updates: mirrors.nwsuaf.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch :- will be installed
--> Finished Dependency Resolution Dependencies Resolved ================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
epel-release noarch - extras k Transaction Summary
================================================================================
Install Package Total download size: k
······
······
······
npm http https://registry.npmjs.org/qs/-/qs-0.6.4.tgz
npm WARN engine formidable@1.0.: wanted: {"node":"<0.9.0"} (current: {"node":"v0.10.36","npm":"1.3.6"})
express@3.2. node_modules/express
├── methods@0.0.
├── fresh@0.1.
├── range-parser@0.0.
├── cookie-signature@1.0.
├── buffer-crc32@0.2.
├── cookie@0.0.
├── commander@0.6.
├── mkdirp@0.3.
├── send@0.1. (mime@1.2.)
├── debug@2.2. (ms@0.7.)
└── connect@2.7. (pause@0.0., qs@0.6., bytes@0.2., formidable@1.0.)
---> 66738118fe5d
Removing intermediate container cad428ec3167
Step : EXPOSE
---> Running in 9ee7937e5835
---> f6ccd16494ac
Removing intermediate container 9ee7937e5835
Step : CMD node /src/index.js
---> Running in 9ca19e7392e9
---> ae5f980eea52
Removing intermediate container 9ca19e7392e9
Successfully built ae5f980eea52
[xiejdm@localhost src]$
5.查看我的镜像
[xiejdm@localhost src]$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
gideon/centos-node-hello latest ae5f980eea52 About a minute ago MB
nodejs_hello/node latest 2daac5743daa minutes ago 544.7 MB
gideon/nodejs latest f30730d7c260 days ago 544.7 MB
nginx latest 6886fb5a9b8d days ago 132.8 MB
ubuntu latest d2a0ecffe6fa weeks ago 188.3 MB
centos centos7 7322fbe74aa5 weeks ago 172.2 MB
centos latest 7322fbe74aa5 weeks ago 172.2 MB
hello-world latest 91c95931e552 months ago B
[xiejdm@localhost src]$
6.运行刚刚生成的镜像,并将容器的8080端口映射到主机的49161端口
[xiejdm@localhost src]$ docker run -p : -d gideon/centos-node-hello
71baf591eb27a2373daf5a802ee9406e635878ee1b1fcd047eb3f39e476b4406
[xiejdm@localhost src]$
7.在本机输入localhost:49161,访问helloword应用。

备注: CentOS 7中增加EPEL库,直接使用yum install epel-release即可(CentOS 5/6则需要下载对应的rpm包然后进行安装)。
参考:http://docs.docker.com/examples/nodejs_web_app/
Docker 生成Node.js web app(含端口映射)的更多相关文章
- [Docker] Build a Simple Node.js Web Server with Docker
Learn how to build a simple Node.js web server with Docker. In this lesson, we'll create a Dockerfil ...
- node.js Web应用框架Express.js(一)
什么是Express.js Express 是一个简洁而灵活的 node.js Web应用框架, 提供一系列强大特性帮助你创建各种Web应用,提供丰富的HTTP工具以及来自Connect框架的中间件随 ...
- KoaHub.js是基于 Koa.js 平台的 Node.js web 快速开发框架
koahubjs KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架.可以直接在项目里使用 ES6/7(Generator Function, Class, A ...
- iKcamp|基于Koa2搭建Node.js实战(含视频)☞ 错误处理
沪江CCtalk视频地址:https://www.cctalk.com/v/15114923887518 处理错误请求 爱能遮掩一切过错. 当我们在访问一个站点的时候,如果访问的地址不存在(404), ...
- iKcamp|基于Koa2搭建Node.js实战(含视频)☞ 记录日志
沪江CCtalk视频地址:https://www.cctalk.com/v/15114923883523 log 日志中间件 最困难的事情就是认识自己. 在一个真实的项目中,开发只是整个投入的一小部分 ...
- iKcamp|基于Koa2搭建Node.js实战(含视频)☞ 处理静态资源
视频地址:https://www.cctalk.com/v/15114923882788 处理静态资源 无非花开花落,静静. 指定静态资源目录 这里我们使用第三方中间件: koa-static 安装并 ...
- iKcamp|基于Koa2搭建Node.js实战(含视频)☞ 视图Nunjucks
视频地址:https://www.cctalk.com/v/15114923888328 视图 Nunjucks 彩虹是上帝和人类立的约,上帝不会再用洪水灭人. 客户端和服务端之间相互通信,传递的数据 ...
- node.js Web应用框架Express入门指南
node.js Web应用框架Express入门指南 作者: 字体:[增加 减小] 类型:转载 时间:2014-05-28 我要评论 这篇文章主要介绍了node.js Web应用框架Express入门 ...
- 利用OpenShift托管Node.js Web服务进行微信公众号开发
最近写了一个微信的翻译机器人.用户只要关注该公众号,发送英文的消息,就能收到中文翻译的回复.有兴趣的读者可以扫描下面的二维码关注该公众号,尝试发送英文单词试试看.(有时候第一次发送单词会收到“该公众号 ...
随机推荐
- Apache 2.4.7在CentOS6.4中安装配置反向代理解决单外网IP对应多个内网主机的方法实践
欢迎转载,转载时请保留全文及出处. Apache 2.4.7在CentOS6.4中安装配置反向代理解决单外网IP对应多个内网主机的方法实践 Apache安装 下载源程序(http://httpd.ap ...
- Visual Studio .NET、.NET Framework和C#之间的联系
Visual Studio .NET是一种集成开发环境(IDE),它包含3种高级程序设计语言,C#就是其中的一种:Visual Studio .NET之所以能把这三种语言有机结合起来并具有与平台无关的 ...
- Link-Cut-Tree题目泛做(为了对应自己的课件)
题目1:BZOJ 2049 洞穴勘测 #include <bits/stdc++.h> #define L(x) c[x][0] #define R(x) c[x][1] using na ...
- git push和git pull
git push git push如果直接使用,不加repository和refspec,那么首先根据当前branch的branch name,在配置文件中找到branch.branchName.re ...
- 用CSS截断字符串
方法一: <div style="width:300px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;&q ...
- 远程复制 scp命令
定义 本机为A,用户名为usera,登录远程主机B的为userb,IP为remote_ip 1. 从B 拷贝文件到A机器 用下面的命令 scp userb@remote_ip:remote_path ...
- 【转】生产环境MySQL Server核心参数的配置
⑴ lower_case_table_names ● 推荐理由 GNU/Linux 平台,对数据库.表.存储过程等对象名称大小 ...
- tuple只有一个元素的时候,必须要加逗号
In [1]: a = (1) In [2]: a Out[2]: 1 In [3]: a = (1,) In [4]: a Out[4]: (1,) 这是因为括号()既可以表示tuple,又可以表示 ...
- Roads in the North(POJ 2631 DFS)
Description Building and maintaining roads among communities in the far North is an expensive busine ...
- linux中如何使用微软鼠标的第4、5键
虽说使用linux的 人大都对微软没什么好感,但不能否认微软确实也出了不少好东西呀,比如微软鼠标(IE系列) icon_smile.gif IE 2.0和以上版本都有5个按钮,除了正常的左中右外,两侧 ...