一上午的时间看文档,发现docker功能还真多。。
草稿太难看了 就简单说下建立过程
安装
环境 Ubuntu Trusty 14.04 (LTS) (64-bit)
$ sudo apt-get update
$ sudo apt-get install docker.io
$ sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker
$ sudo sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/docker.io
测试
sudo docker run -i -t ubuntu /bin/bash
你发现进入另一个系统,你就成功了
安装node。js并制作镜像
偷懒下
half@half-All-Series:~/src$ pwd
/home/half/src
half@half-All-Series:~/src$ ls
Dockerfile package.json server.js
half@half-All-Series:~/src$ cat package.json
{
"name": "mada0",
"private": true,
"version": "0.0.1",
"description": "Node.js Hello world app on CentOS using docker",
"author": "Daniel Gasienica <daniel@gasienica.ch>",
"dependencies": {
"express": "4.8.5"
}
}
half@half-All-Series:~/src$ cat server.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);
console.log('Running on http://localhost:' + PORT);
half@half-All-Series:~/src$ cat Dockerfile
FROM node
ADD . /home/half/src
WORKDIR /home/half/src
# install your application's dependencies
RUN npm install
# replace this with your application's default port
EXPOSE 8888
# replace this with your main "server" script file
CMD [ "node", "server.js" ]
制作image
half@half-All-Series:~/src$ sudo docker build -t halfming/mada0 .
漫长的等待之后
half@half-All-Series:~/src$ sudo docker images
[sudo] password for half:
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
halfming/mada0 latest ba4823af39af 35 seconds ago 866.7 MB
node 0.11.13-onbuild 7ca564a2aaa2 2 weeks ago
查看
half@half-All-Series:~/src$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2d78f5763f33 halfming/mada0:latest node server.js 18 seconds ago Up 17 seconds 0.0.0.0:49160->8080/tcp, 8888/tcp cocky_morse
端口49160 127.0.0.1:49160 看下有没有成功
收尾
给个tag
half@half-All-Series:~/src$ sudo docker tag ba4823af39af halfming/mada0:init
half@half-All-Series:~/src$ sudo docker images halfming/mada0
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
halfming/mada0 latest ba4823af39af 26 minutes ago 866.7 MB
halfming/mada0 init ba4823af39af 26 minutes ago 866.7 MB
push到服务器。。
half@half-All-Series:~/src$ sudo docker push halfming/mada0
比想象的麻烦多了 明天geoman harp
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。