Home > Archives > Docker示例

Docker示例

Publish:

Docker 安装与配置

这个问题自己解决

执行步骤

File dir

1
2
3
4
demo
|-- Dockerfile
|-- index.js
`-- package.json

CLI

1
2
3
4
5
6
7
8
9
10
mkdir demo
cd demo
vim Dockerfile
vim index.js
vim package.json
docker build .
docker images
docker run -p 3000:3000 -it 32c9a5b01b73
curl http://127.0.0.1:3000
curl http://129.28.122.72:3000/

Dockerfile

1
2
3
4
5
6
FROM node:6.2.2
WORKDIR /app
ADD . /app
RUN npm install
EXPOSE 300
CMD npm start

index.js

var express = require('express');
var app = express();
app.get('/', function(req, res) {
  res.send('Hello World!');
});
var server = app.listen(3000, function() {
  var host = server.address().address;
  var port = server.address().port;
  
  console.log("Example app listening at 'http://%s:%s'", host, port);
})

package.json

{
  "name": "myapp",
  "version": "1.0.0",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "express": "^4.16.2"
  }
}

参考

声明: 本文采用 BY-NC-SA 授权。转载请注明转自: Ding Bao Guo