{ "name": "docker-centos-hello", "private": true, "version": "0.0.1", "description": "Node.js Hello world app on CentOS using docker", "author": "Daniel Gasienica <daniel@gasienica.ch>", "dependencies": { "express": "3.2.4" } }
Step 2.编写逻辑文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[root@yuanxiaolong nodejs]# cat index.js
var express = require('express');
// Constants var PORT = 8088;
// App var app = express(); app.get('/', function (req, res) { res.send('Hello world\n'); });
app.listen(PORT); console.log('Running on http://localhost:' + PORT);
Step 3.编写Dockerfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
root@yuanxiaolong nodejs]# cat Dockerfile
# DOCKER-VERSION 0.3.4 FROM centos:centos6
# Enable EPEL for Node.js RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm # Install Node.js and npm RUN yum install -y npm
# Bundle app source COPY . /src # Install app dependencies RUN cd /src; npm install
docker run -p 49160:8088-d yuanxiaolong/centos-node-hello
Step 7.验证
1 2 3 4 5 6 7 8 9 10 11 12 13 14
[root@yuanxiaolong ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 163ee06b3176 yuanxiaolong/centos-node-hello:latest node /src/index.js 17 hours ago Up 17 hours 8088/tcp, 0.0.0.0:49160->8080/tcp mad_shockley