docker nodejs 기본 응용

2360 단어
1. docker 환경 설치
2. nodejs  응용 레이아웃
package.json
{
  "name": "docker-centos-hello",
  "private": true,
  "version": "0.0.1",
  "description": "Node.js Hello world app on CentOS using docker",
  "author": "Daniel Gasienica <[email protected]>",
  "dependencies": {
    "express": "3.2.4"
  }
}

3. index. js express 사용
var express = require('express');

// Constants
var PORT = 8080;

// App
var app = express();
app.get('/', function (req, res) {
  res.send('Hello world
'); }); app.listen(PORT); console.log('Running on http://localhost:' + PORT);

4. Dockerfile 파일 생 성
FROM    centos:centos6

# Enable Extra Packages for Enterprise Linux (EPEL) for CentOS
RUN     yum install -y epel-release
# Install Node.js and npm
RUN     yum install -y nodejs npm

# Install app dependencies
COPY package.json /src/package.json
RUN cd /src; npm install

# Bundle app source
COPY . /src

EXPOSE  8080
CMD ["node", "/src/index.js"]

5. 미 러 만 들 기
docker build -t dalong/centos-node .

6. 생 성 된 미 러 실행
docker run -p 49160:8080 -d dalong/centos-node

그 중 8080 은 용기 node 의 포트 입 니 다.  49160 은 docker 숙주 환경 노출 포트 입 니 다.
7. 테스트 의 효과
   
curl -i localhost:49160

HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 12
Date: Tue, 26 Jan 2016 06:55:32 GMT
Connection: keep-alive

Hello world

좋은 웹페이지 즐겨찾기