@ValenW
2016-05-08T09:16:05.000000Z
字数 1944
阅读 1542
列表项
学习 博客 作业
Docker 是一个开源项目,诞生于 2013 年初,最初是 dotCloud 公司内部的一个业余项目。它基于 Google 公司推出的 Go 语言实现。 项目后来加入了 Linux 基金会,遵从了 Apache 2.0 协议,项目代码在 GitHub 上进行维护。
下面的图片比较了 Docker 和传统虚拟化方式的不同之处,可见容器是在操作系统层面上实现虚拟化,直接复用本地主机的操作系统,而传统方式则是在硬件层面实现。

| 特性 | 容器 | 虚拟机 |
|---|---|---|
| 启动 | 秒级 | 分钟级 |
| 硬盘使用 | 一般为 MB | 一般为 GB |
| 性能 | 接近原生 | 弱于 |
| 系统支持量 | 单机支持上千个容器 | 一般几十个 |
$ curl -fsSL https://get.docker.com/ | sh$ curl -fsSL https://get.docker.com/gpg | sudo apt-key add -
然后执行命令$ docker run hello-world如果输出如下,表示安装成功。
Unable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-world535020c3e8ad: Pull completeaf340544ed62: Pull completeDigest: sha256:a68868bfe696c00866942e8f5ca39e3e31b79c1e50feaee4ce5e28df2f051d5cStatus: Downloaded newer image for hello-world:latestHello from Docker.This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps:1. The Docker Engine CLI client contacted the Docker Engine daemon.2. The Docker Engine daemon pulled the "hello-world" image from the Docker Hub.3. The Docker Engine daemon created a new container from that image which runs theexecutable that produces the output you are currently reading.4. The Docker Engine daemon streamed that output to the Docker Engine CLI client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker Hub account:https://hub.docker.comFor more examples and ideas, visit:https://docs.docker.com/userguide/
使用命令
$ sudo docker pull ubuntu:12.04
就可以从Docker远程服务器中拉取ubuntu 12.04版本的镜像。
$ sudo docker run -t -i ubuntu:14.04 /bin/bash
就可以进入ubuntu镜像的命令行了。
配置环境,以Node.js为例:
apt-get install python-software-properties python g++ makeadd-apt-repository ppa:chris-lea/node.jsapt-get updateapt-get install nodejs npm
安装express
npm install express -gd
初始化网站目录
cd /mnt/express nodeservercd nodeservernpm install
然后得编辑下 app.js
vim app.js
先把默认端口号3000改为80
app.set('port', process.env.PORT || 80);
再注释掉以下代码
app.get('/', routes.index);app.get('/users', user.list);
然后用forever实现后台启动nodejs
npm install foreverforever start -w app.js
这样服务就启动了,可以用ip访问。