一上午的時間看文檔,發現docker功能還真多。。
草稿太難看了 就簡單說下創建過程node
環境 Ubuntu Trusty 14.04 (LTS) (64-bit)docker
$ 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
測試express
sudo docker run -i -t ubuntu /bin/bash
你發現進入另外一個系統,你就成功了npm
偷懶下json
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" ]
製做imageubuntu
half@half-All-Series:~/src$ sudo docker build -t halfming/mada0 .
漫長的等待以後bash
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 看下有沒有成功app
給個tagtcp
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