docker有哪些docker web管理 swarm工具比较好用

更多频道内容在这里查看
爱奇艺用户将能永久保存播放记录
过滤短视频
暂无长视频(电视剧、纪录片、动漫、综艺、电影)播放记录,
使用您的微博帐号登录,即刻尊享微博用户专属服务。
使用您的QQ帐号登录,即刻尊享QQ用户专属服务。
使用您的人人帐号登录,即刻尊享人人用户专属服务。
按住视频可进行拖动
把视频贴到Blog或BBS
当前浏览器仅支持手动复制代码
视频地址:
flash地址:
html代码:
通用代码:
通用代码可同时支持电脑和移动设备的分享播放
收藏成功,可进入查看所有收藏列表
方式1:用手机看
用爱奇艺APP或微信扫一扫,在手机上继续观看:
docker web管理
方式2:一键下载至手机
限爱奇艺安卓6.0以上版本
使用微信扫一扫,扫描左侧二维码,下载爱奇艺移动APP
其他安装方式:手机浏览器输入短链接http://71.am/udn
下载安装包到本机:&&
设备搜寻中...
请确保您要连接的设备(仅限安卓)登录了同一爱奇艺账号 且安装并开启不低于V6.0以上版本的爱奇艺客户端
连接失败!
请确保您要连接的设备(仅限安卓)登录了同一爱奇艺账号 且安装并开启不低于V6.0以上版本的爱奇艺客户端
部安卓(Android)设备,请点击进行选择
请您在手机端下载爱奇艺移动APP(仅支持安卓客户端)
使用微信扫一扫,下载爱奇艺移动APP
其他安装方式:手机浏览器输入短链接http://71.am/udn
下载安装包到本机:&&
爱奇艺云推送
请您在手机端登录爱奇艺移动APP(仅支持安卓客户端)
使用微信扫一扫,下载爱奇艺移动APP
180秒后更新
打开爱奇艺移动APP,点击“我的-扫一扫”,扫描左侧二维码进行登录
没有安装爱奇艺视频最新客户端?
爸爸去哪儿2游戏 立即参与
docker web管理
播放量数据:
4,014人已订阅
你可能还想订阅他们:
{{#needAdBadge}} 广告{{/needAdBadge}}
&正在加载...
您使用浏览器不支持直接复制的功能,建议您使用Ctrl+C或右键全选进行地址复制
安装爱奇艺视频客户端,
马上开始为您下载本片
5秒后自动消失
&li data-elem="tabtitle" data-seq="{{seq}}"& &a href="javascript:void(0);"& &span>{{start}}-{{end}}&/span& &/a& &/li&
&li data-downloadSelect-elem="item" data-downloadSelect-selected="false" data-downloadSelect-tvid="{{tvid}}"& &a href="javascript:void(0);"&{{pd}}&/a&
选择您要下载的《
色情低俗内容
血腥暴力内容
广告或欺诈内容
侵犯了我的权力
还可以输入
您使用浏览器不支持直接复制的功能,建议您使用Ctrl+C或右键全选进行地址复制查看: 3037|回复: 18
利用Docker构建开发环境
论坛徽章:349
大背景–虚拟化技术历史
计算机虚拟化技术由来已久,从硬件仿真到全虚拟化,再到准虚拟化和操作系统虚拟化,各种技术粉墨登场,种类繁多,说实在的有点眼花缭乱和复杂;但用户的核心诉求一直是比较简单的,降低信息技术(IT)的运营成本,提高资源利用率,提高安全性和可靠性等等;虽说用户的核心诉求比较简单,但每个时代的需求场景却是不同的。在大型机时代,虚拟化技术被用来支持多个用户能够同时使用大型机,在x86架构时代,随着企业服务的大规模部署,虚拟化技术主要是用来提高企业资源的利用率,而现如今,随着云计算时代的到来,人们对应用的安全性、隔离性越来越高,对于部署的标准化以及虚拟机的性能要求越来越高。现如今,一种叫Linux容器的虚拟化技术逐渐得到广泛的应用,它的优点有许多,本文不一一赘述,有太多的文章可以参考。
论坛徽章:349
什么是Docker?
docker的英文本意是码头工人,也就是搬运工,这种搬运工搬运的是集装箱(Container),集装箱里面装的可不是商品货物,而是任意类型的App,Docker把App(叫Payload)装在Container内,通过Linux Container技术的包装将App变成一种标准化的、可移植的、自管理的组件,这种组件可以在你的latop上开发、调试、运行,最终非常方便和一致地运行在production环境下。
Docker的核心底层技术是LXC(Linux Container),Docker在其上面加了薄薄的一层,添加了许多有用的功能。这篇stackoverflow上的问题和答案很好地诠释了Docker和LXC的区别,能够让你更好的了解什么是Docker, 简单翻译下就是以下几点:
Docker提供了一种可移植的配置标准化机制,允许你一致性地在不同的机器上运行同一个Container;而LXC本身可能因为不同机器的不同配置而无法方便地移植运行;
Docker以App为中心,为应用的部署做了很多优化,而LXC的帮助脚本主要是聚焦于如何机器启动地更快和耗更少的内存;
Docker为App提供了一种自动化构建机制(Dockerfile),包括打包,基础设施依赖管理和安装等等;
Docker提供了一种类似git的Container版本化的机制,允许你对你创建过的容器进行版本管理,依靠这种机制,你还可以下载别人创建的Container,甚至像git那样进行合并;
Docker Container是可重用的,依赖于版本化机制,你很容易重用别人的Container(叫Image),作为基础版本进行扩展;
Docker Container是可共享的,有点类似github一样,Docker有自己的INDEX,你可以创建自己的Docker用户并上传和下载Docker Image;
Docker提供了很多的工具链,形成了一个生态系统;这些工具的目标是自动化、个性化和集成化,包括对PAAS平台的支持等;
那么Docker有什么用呢?对于运维来说,Docker提供了一种可移植的标准化部署过程,使得规模化、自动化、异构化的部署成为可能甚至是轻松简单的事情;而对于开发者来说,Docker提供了一种开发环境的管理方法,包括映像、构建、共享等功能,而后者是本文的主题。
论坛徽章:349
Docker的安装和构成Docker官方本身提供了非常具体的安装教程,这里不说具体的安装过程,请参考,重要的是描述下原理和安装完成后的结构,好对Docker更好的了解。 由于LXC本身不支持Mac内核,因此需要跑一个VirtualBox虚拟机()来安装,幸好Docker社区提供了一个非常方便的工具boot2docker(其实就是一个VBoxManage的包装shell脚本),用于安装Mac下的整个Docker环境。具体的结构如下:如图所示,安装完成后,具体情况如下:在Mac的home目录~/.boot2docker下创建了虚拟机所需要的文件,其中boot2docker.iso是虚拟机映像,这是一个由CD-ROM引导的TinyCoreLinux系统;而boot2docker-vm.vmdk文件则是你的虚拟机磁盘,你所有的持久化数据都存放在这里,包括docker创建的lxc容器等文件。在Mac下,docker被分为客户端docker-client和服务端docker-daemon两部分,如果是在linux(比如ubuntu),实际上则是同一个可执行文件同时充当客户端和服务端。docker-daemon可以监听unix scoket,也可以在tcp socket(默认端口为4234),docker-client会通过一个叫DOCKER_HOST的环境变量读取服务地址和端口,因此你应该在你的bash_profile文件里面添加这么一行:
[color=rgb(170, 170, 170) !important]1
[color=rgb(170, 170, 170) !important]2
[color=teal !important]export [color=rgb(0, 45, 122) !important]DOCKER_HOST[color=rgb(0, 111, 224) !important]=[color=rgb(0, 45, 122) !important]tcp[color=rgb(0, 111, 224) !important]:[color=rgb(153, 153, 153) !important]//127.0.0.1:4243
docker-daemon跑在虚拟机上,这个程序实际上就是接收docker-client发送过来的消息命令,创建、启动和销毁lxc容器,以及docker本身的版本管理、映像存储等等 运行你的第一个docker容器 安装完成后,就差不多可以开始创建和运行docker容器了,在这之前,你首先得下载一个Image,什么是Image?我们先来了解docker的2个基础概念:Image和Container。Container和Image 在Docker的世界里,Image是指一个只读的层(Layer),这里的层是AUFS里的概念,最直观的方式就是看一下docker官方给出的图:Docker使用了一种叫AUFS的文件系统,这种文件系统可以让你一层一层地叠加修改你的文件,最底下的文件系统是只读的,如果需要修改文件,AUFS会增加一个可写的层(Layer),这样有很多好处,例如不同的Container可以共享底层的只读文件系统(同一个Kernel),使得你可以跑N多个Container而不至于你的硬盘被挤爆了!这个只读的层就是Image!而如你所看到的,一个可写的层就是Container。那Image和Container的区别是什么?很简单,他们的区别仅仅是一个是只读的层,一个是可写的层,你可以使用docker commit 命令,将你的Container变成一个Image,也就是提交你所运行的Container的修改内容,变成一个新的只读的Image,这非常类似于git commit命令,感觉真棒!实际上这就是Docker对Container映像的版本管理基石,AUFS文件系统实在是太美妙了,更多细节可以参考DotCloud的。
论坛徽章:349
运行和退出在了解了Image和Container的概念后,我们可以开始下载一个Image,Docker的好处就是提供了一个类似github的Image仓库管理,你可以非常方便pull别人的Image下来运行,例如,我们可以下载一个ubuntu Image:
[color=rgb(170, 170, 170) !important]1
[color=rgb(170, 170, 170) !important]2
[color=teal !important]docker [color=teal !important]pull [color=rgb(0, 45, 122) !important]ubuntu[color=rgb(0, 111, 224) !important]:[color=rgb(0, 153, 153) !important]13.10[color=rgb(0, 111, 224) !important]
这里的13.10是一个Tag,类似于git的tag,这里的tag可以为你制定一个ubuntu的版本。下载完成后,执行docker images命令可以列出你已经下载或者自己构建的image:(请允许我使用可爱的马赛克
)你可以看到ubuntu:13.10的大小为178MB,以及它的IMAGE ID。 现在我们开始运行一个Container,命令很简单,例如我们想运行一个执行Shell终端的Container:如你看到的,你已经进入到一个Shell里面,可以执行你想执行的任何命令,就和在ubuntu里面一样,进去后默认是在根目录/下,可以看到经典的unix/linux目录结构,以及你所运行的bash版本等信息。你可以给你的Container定一个名字,通过–name选项,例如这里命名了shell,日后你就可以直接用这个名字引用Contanier。退出一个Container也很简单,你直接exit就好了。 其他更多的命令这里不做赘述,因为官方的文档已经非常全面,这里只是给一个直观的初步印象。下面进入主题。利用Docker搭建开发环境我们先看看程序员在搭建开发环境时遇到的一些问题:软件安装麻烦,比如很多公司都使用redhat,一般开发人员又不给root,安装一个nginx或者是mysql都得自己下载编译安装 权限问题,没有root,一些软件无法运行,例如dnsmasq;没有root,无法修改hosts,无法netstat -nptl,无法tcpdump,无法iptable隔离性差,例如不同的开发人员如果在同一台主机环境下共享开发,虽然是用户隔离,但端口如果不规范可能会冲突;同一个Mysql如果权限管理不好很有可能误删别人的数据可移植性差,例如和生产环境不一致,开发人员之间也无法共享;更严重的情况是当有新人入职时,通常需要又折腾一遍开发环境,无法快速搭建
这些问题可以通过在本地搭建虚拟机来解决,但虚拟机是一个很笨重的解决方案,Docker是一个非常轻量级的方案,而且还拥有虚拟机没有的一些功能,例如标准化Image,Image共享等,更重要的是,利用Docker,你可以运行非常多的容器,在你的Mac下搭建一个分布式的开发环境根本不是什么大的问题,而且对内存、磁盘和cpu的消耗相比传统的虚拟机要低许多,这些都要归功于AUFS和LXC这两大神奇的技术。
论坛徽章:349
构建基础Image想要搭建一个节省磁盘空间和扩展性良好的开发环境,最重要的第一步就是构建一个基础性的Image,比如你的主要开发语言是Ruby,那么你肯定需要一个已经安装好以下工具的基础Image:rubybundlergem
然后在此基础上,你可以扩展这个基础的Image(下面叫base)为不同的开发环境,例如rails,或者是nats。当然,你的这个base也可以从别人的Image扩展而来,还记得我们刚刚pull下来的ubuntu:13.10这个Image吗?你可以从这个Image扩展开始构建你的base,如何做呢?Docker提供了一种标准化的DSL方式,你只需要编写一个Dockerfile,运行docker build指令,就可以构建你自己的Image,这有点像Makefile和make命令一样,只是大家要构建的内容和构建语言不同。Dockerfile的语法请参考,这里给出上面提到的Ruby开发的base Dockerfile示例:
[color=rgb(170, 170, 170) !important]1
[color=rgb(170, 170, 170) !important]2
[color=rgb(170, 170, 170) !important]3
[color=rgb(170, 170, 170) !important]4
[color=rgb(170, 170, 170) !important]5
[color=teal !important]FROM [color=rgb(0, 45, 122) !important]ubuntu[color=rgb(0, 111, 224) !important]:[color=rgb(0, 153, 153) !important]13.10[color=rgb(0, 111, 224) !important]
[color=teal !important]RUN [color=rgb(0, 45, 122) !important]apt[color=rgb(0, 111, 224) !important]-[color=teal !important]get [color=teal !important]update
[color=teal !important]RUN [color=rgb(0, 45, 122) !important]apt[color=rgb(0, 111, 224) !important]-[color=teal !important]get [color=rgb(0, 45, 122) !important]install[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-y[color=rgb(0, 111, 224) !important] [color=teal !important]ruby [color=rgb(0, 45, 122) !important]ruby[color=rgb(0, 111, 224) !important]-[color=teal !important]dev [color=teal !important]gem
[color=teal !important]RUN [color=teal !important]gem [color=teal !important]install bundler[color=rgb(0, 111, 224) !important]
这里只用到了很简单的2个指令:FROM和RUN,FROM指定了我们要扩展的Image,RUN指定我们要运行的命令,这里是安装ruby,gem、bundler等软件。写好Dockerfile后,运行以下指令就可以创建你的base image了:
[color=rgb(170, 170, 170) !important]1
[color=rgb(170, 170, 170) !important]2
[color=teal !important]docker [color=rgb(0, 45, 122) !important]build[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]--[color=rgb(0, 45, 122) !important]rm[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-t[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]dev[color=rgb(0, 111, 224) !important]:base[color=rgb(0, 111, 224) !important] [color=rgb(51, 51, 51) !important].[color=rgb(0, 111, 224) !important]
-t 选项是你要构建的base image的tag,就好比ubuntu:13.10一样 –rm 选项是告诉Docker在构建完成后删除临时的Container,Dockerfile的每一行指令都会创建一个临时的Container,一般你是不需要这些临时生成的Container的 如你所想,我们可以像运行ubuntu:13.10那样运行我们的base了:
[color=rgb(170, 170, 170) !important]1
[color=rgb(170, 170, 170) !important]2
[color=teal !important]docker [color=rgb(0, 45, 122) !important]run[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]i[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]t[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]--[color=teal !important]name [color=teal !important]ruby [color=rgb(0, 45, 122) !important]dev[color=rgb(0, 111, 224) !important]:[color=teal !important]base irb[color=rgb(0, 111, 224) !important]
这里我们使用dev:base这个Image运行了一个irb解释器(Ruby的交互式解释器)。 在构建完base之后,你可以依样画葫芦构建你的rails环境,很简单,只需要FROM dev:base,然后RUN安装你的rails组件就可以了,不再赘述。最终你可能构建的开发环境是这样的:如上图所示,base和service都是从ubutnu:13.10继承而来,他们作为不同的基础开发环境,base是ruby开发环境(也许命名为dev:ruby更为合适?),而service是一些基础数据服务,例如mysql,memcache,我建议将这些第三方组件集中在一个Container中,因为他们的环境不经常修改,可以作为一种底层服务Container运行,除非你需要构建分布式的服务,例如memcache集群,那可以继续拆分。
论坛徽章:349
指定Image入口当你构建完你的base Image和其他应用的Image之后,你就可以启动这些Image了,还记得前面我们给出的运行命令吗?
[color=rgb(170, 170, 170) !important]1
[color=rgb(170, 170, 170) !important]2
[color=teal !important]docker [color=rgb(0, 45, 122) !important]run[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]i[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]t[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]--[color=teal !important]name [color=teal !important]shell [color=rgb(0, 45, 122) !important]dev[color=rgb(0, 111, 224) !important]:[color=rgb(0, 45, 122) !important]base[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]bin[color=rgb(0, 111, 224) !important]/bash[color=rgb(0, 111, 224) !important]
这里我们运行了一个bash,这样你就可以在shell里面执行你所想要执行的任何命令了,但是我们有时候并不想每次都启动一个shell,接着再在shell里面启动我们的程序,比如一个mysql,而是想一启动一个容器,mysql服务就自动运行了,这很简单,Dockerfile提供了CMD和ENTRYPOINT这2个指令,允许你指定一个Image启动时的默认命令。CMD和ENTRYPOINT的区别是CMD的参数可以由docker run指令指定的参数覆盖,而ENTRYPOINT则不可以。例如我们想运行一个memcached服务,可以这么写Dockerfile:
[color=rgb(170, 170, 170) !important]1
[color=rgb(170, 170, 170) !important]2
[color=rgb(170, 170, 170) !important]3
[color=teal !important]FROM [color=rgb(0, 45, 122) !important]ubuntu[color=rgb(0, 111, 224) !important]:[color=rgb(0, 153, 153) !important]13.10[color=rgb(0, 111, 224) !important]
[color=teal !important]RUN [color=rgb(0, 45, 122) !important]apt[color=rgb(0, 111, 224) !important]-[color=teal !important]get [color=rgb(0, 45, 122) !important]install[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-y[color=rgb(0, 111, 224) !important] [color=teal !important]memcached [color=teal !important]CMD [color=rgb(0, 45, 122) !important]memcached[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-u[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]root[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-p[color=rgb(0, 111, 224) !important] [color=rgb(0, 153, 153) !important]40000[color=rgb(0, 111, 224) !important]
或者可以这么写:
[color=rgb(170, 170, 170) !important]1
[color=rgb(170, 170, 170) !important]2
[color=rgb(170, 170, 170) !important]3
[color=teal !important]FROM [color=rgb(0, 45, 122) !important]ubuntu[color=rgb(0, 111, 224) !important]:[color=rgb(0, 153, 153) !important]13.10[color=rgb(0, 111, 224) !important]
[color=teal !important]RUN [color=rgb(0, 45, 122) !important]apt[color=rgb(0, 111, 224) !important]-[color=teal !important]get [color=rgb(0, 45, 122) !important]install[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-y[color=rgb(0, 111, 224) !important] [color=teal !important]memcached ENTRYPOINT[color=rgb(0, 111, 224) !important] [color=rgb(51, 51, 51) !important][[color=rgb(221, 17, 68) !important]&memcached&[color=rgb(51, 51, 51) !important],[color=rgb(0, 111, 224) !important] [color=rgb(221, 17, 68) !important]&-u&[color=rgb(51, 51, 51) !important],[color=rgb(0, 111, 224) !important] [color=rgb(221, 17, 68) !important]&root&[color=rgb(51, 51, 51) !important],[color=rgb(0, 111, 224) !important] [color=rgb(221, 17, 68) !important]&-p&[color=rgb(51, 51, 51) !important],[color=rgb(0, 111, 224) !important] [color=rgb(221, 17, 68) !important]&40000&[color=rgb(51, 51, 51) !important][color=rgb(0, 111, 224) !important]
注意不要把memcached启动为后台进程,即加上-d选项,否则docker启动的container会马上stop掉,这点我也觉得比较意外。 接着我们build这个Image:
[color=rgb(170, 170, 170) !important]1
[color=rgb(170, 170, 170) !important]2
[color=teal !important]docker [color=rgb(0, 45, 122) !important]build[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-t[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]dev[color=rgb(0, 111, 224) !important]:memcache[color=rgb(0, 111, 224) !important] [color=rgb(51, 51, 51) !important].[color=rgb(0, 111, 224) !important]
这样,当你build完你的Image后,你可以直接将该Image运行为一个容器,它会自动启动mysql服务:
[color=rgb(170, 170, 170) !important]1
[color=rgb(170, 170, 170) !important]2
[color=teal !important]docker [color=rgb(0, 45, 122) !important]run[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]--[color=teal !important]name [color=rgb(0, 45, 122) !important]memcache_service[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-d[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]dev[color=rgb(0, 111, 224) !important]:memcache[color=rgb(0, 111, 224) !important]
注意使用-d (detach) 选项,这样这个container就会作为后台进程运行了,接着你可以使用docker ps命令查看是否有在运行。磁盘映射大部分时候你会需要把你host主机(宿主)上的目录映射到Container里面,这样你就非常方便地在host主机上编辑代码,然后直接就可以在Container里面运行它们,而不用手动copy到Container里面再重启Container。按理将host的目录映射到guest(指Container)上应该是一件很容易的事情,就好像VMWare那样,但可惜的是,由于Mac上的Docker多了一层虚拟机,因此多了一层周折,你必须先VM上的目录通过sshfs mount到host(指Mac)上,然后再将你的目录或文件copy到这个mount的目录,再将VM上的这个目录映射到Container里,听起来比较拗口,画个图会清晰很多。如上图所示,VM里面的/mnt/sda1/dev/目录(你需要自己创建)通过sshfs命令mount到了host主机(Mac)的~/workspace/dev/目录 ,而VM里的/mnt/sda1/dev/目录又被映射到了Container的/src/目录下,这样你就可以在Container里面的/src/目录下访问你的host文件了。具体如何做呢?首先你需要安装sshfs命令,然后将VM的password写到一个文件中,例如~/.boot2docker/b2d-passwd,在用sshfs命令mount起VM的/mnt/sda1/dev目录:
[color=rgb(170, 170, 170) !important]1
[color=rgb(170, 170, 170) !important]2
[color=rgb(170, 170, 170) !important]3
[color=rgb(170, 170, 170) !important]4
[color=teal !important]brew [color=teal !important]install [color=teal !important]sshfs
[color=teal !important]cat [color=rgb(0, 45, 122) !important]tcuser[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]&[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]~[color=rgb(0, 111, 224) !important]/[color=rgb(51, 51, 51) !important].[color=rgb(0, 45, 122) !important]boot2docker[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]b2d[color=rgb(0, 111, 224) !important]-[color=teal !important]passwd
[color=teal !important]sshfs [color=rgb(0, 45, 122) !important]docker[color=rgb(51, 51, 51) !important]@[color=rgb(0, 45, 122) !important]localhost[color=rgb(0, 111, 224) !important]:[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]mnt[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]sda1[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]dev[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]~[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]workspace[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]dev[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-p[color=rgb(0, 111, 224) !important] [color=rgb(0, 153, 153) !important]2022[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-o[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]reconnect[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-o[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]password_stdin[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]&[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]~[color=rgb(0, 111, 224) !important]/[color=rgb(51, 51, 51) !important].[color=rgb(0, 45, 122) !important]boot2docker[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]b2d[color=rgb(0, 111, 224) !important]-passwd[color=rgb(0, 111, 224) !important]
接着你在run一个Container的时候需要通过-v选项来将/mnt/sda1/dev/映射到/src目录:
[color=rgb(170, 170, 170) !important]1
[color=rgb(170, 170, 170) !important]2
[color=teal !important]docker [color=rgb(0, 45, 122) !important]run[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]i[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-t[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]dev[color=rgb(0, 111, 224) !important]:[color=rgb(0, 45, 122) !important]base[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]v[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]mnt[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]sda1[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]dev[color=rgb(0, 111, 224) !important]:[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]src[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]bin[color=rgb(0, 111, 224) !important]/bash[color=rgb(0, 111, 224) !important]
这样你就可以在你的Container的/src目录下看到你host里的文件了。 磁盘映射还有2个地方需要注意:你的文件实际上是存储在VM里面的,也就是说你需要将你的目录或者文件copy到VM里面,你sshfs之后,就是copy到~/workspace/dev目录下千万不要sshfs mount非/mnt/sda1下的目录,因为VM里面跑的是TinyCoreLinux,这个OS的rootfs是临时性的(放在内存的,实际上就是boot2docker.iso文件里面的一个rootfs),因此其根目录/下的东西(包括/home)根本不会持久化,只有/mnt/sda1这个目录下的才能持久化。如果你放在/home目录下,只要VM一重启,就会丢失的,/mnt/sda1则不会,实际上就是那个~/.boot2docker-vm.vmdk文件挂载到了/mnt/sda1目录下
论坛徽章:349
端口映射和磁盘映射一样,你有时候会需要将Container的端口映射到host主机上,同样蛋疼的是,由于多了一层VM,端口映射也显得比较麻烦。首先你需要设置VirtualBox的端口映射,然后再将Container的端口映射到你的VM里面:具体是这么做的,通过2条命令:
[color=rgb(170, 170, 170) !important]1
[color=rgb(170, 170, 170) !important]2
[color=rgb(170, 170, 170) !important]3
[color=teal !important]boot2docker [color=rgb(0, 45, 122) !important]ssh[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-L[color=rgb(0, 111, 224) !important] [color=rgb(0, 153, 153) !important]8000[color=rgb(0, 111, 224) !important]:[color=rgb(0, 45, 122) !important]localhost[color=rgb(0, 111, 224) !important]:[color=rgb(0, 153, 153) !important]8000[color=rgb(0, 111, 224) !important]
[color=teal !important]docker [color=rgb(0, 45, 122) !important]run[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]i[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]t[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-p[color=rgb(0, 111, 224) !important] [color=rgb(0, 153, 153) !important]8000[color=rgb(0, 111, 224) !important]:[color=rgb(0, 153, 153) !important]8000
也就是说在docker run的时候通过-p选项指定要映射的端口到VM,而boot2docker ssh命令则是将VM的8000端口映射到了host(Mac)的8000端口,这样你就可以通过Mac的localhost:8000访问Container的8000端口了。 其实,有另一种解决方案就是你不用映射到host(Mac),而是直接登录到VM里面进行访问就好了,boot2docker ssh就可以登录到VM,这样就类似于你的host是ubuntu,但这种解决方案的问题是这个ubuntu太弱了(TinyCoreLinux),如果你在这个ubuntu里面开发代码,或者是运行浏览器,是非常蛋疼的事情,关键还是这个ubuntu是每次重启都会复原的!所以我建议还是做多一层映射好了。 最后,实际上在VM里面,你是可以直接访问所有的Container的端口的,因为VM到Container的网络都是桥接的。其他的一些坑在使用的过程中,还遇到一些不少的坑:/etc/hosts文件无法修改,这样你就不能自己做域名解析VM的系统时间是UTC +0000的,而且貌似无法修改Container的IP无法指定为静态IP,因此每次重启Container时,IP可能会变化
第1个问题的解决方案是通过安装dnsmasq软件来做域名解析:
[color=rgb(170, 170, 170) !important]1
[color=rgb(170, 170, 170) !important]2
[color=rgb(170, 170, 170) !important]3
[color=rgb(170, 170, 170) !important]4
[color=rgb(170, 170, 170) !important]5
[color=rgb(170, 170, 170) !important]6
[color=rgb(170, 170, 170) !important]7
[color=rgb(170, 170, 170) !important]8
[color=rgb(170, 170, 170) !important]9
[color=rgb(170, 170, 170) !important]10
[color=rgb(170, 170, 170) !important]11
[color=rgb(170, 170, 170) !important]12
[color=rgb(170, 170, 170) !important]13
[color=rgb(170, 170, 170) !important]14
[color=rgb(170, 170, 170) !important]15
[color=rgb(170, 170, 170) !important]16
[color=rgb(170, 170, 170) !important]17
[color=rgb(170, 170, 170) !important]18
[color=rgb(170, 170, 170) !important]19
[color=rgb(170, 170, 170) !important]20
[color=rgb(170, 170, 170) !important]21
[color=rgb(170, 170, 170) !important]22
[color=rgb(170, 170, 170) !important]23
[color=rgb(170, 170, 170) !important]24
[color=rgb(170, 170, 170) !important]25
[color=rgb(170, 170, 170) !important]26
[color=rgb(184, 92, 0) !important]# 首先,在你的Container里面安装dnsmasq软件:
[color=rgb(0, 45, 122) !important]apt[color=rgb(0, 111, 224) !important]-[color=teal !important]get [color=teal !important]install [color=rgb(0, 45, 122) !important]dnsmasq
[color=rgb(184, 92, 0) !important]# 将以下文本添加到 /etc/dnsmasq.conf文件的最后:
[color=rgb(0, 45, 122) !important]listen[color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]address[color=rgb(0, 111, 224) !important]=[color=rgb(0, 153, 153) !important]127.0.0.1[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]resolv[color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]file[color=rgb(0, 111, 224) !important]=[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]etc[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]resolv[color=rgb(51, 51, 51) !important].[color=rgb(0, 45, 122) !important]dnsmasq[color=rgb(51, 51, 51) !important].[color=teal !important]conf [color=rgb(0, 45, 122) !important]conf[color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]dir[color=rgb(0, 111, 224) !important]=[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]etc[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]dnsmasq[color=rgb(51, 51, 51) !important].d[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]user[color=rgb(0, 111, 224) !important]=[color=rgb(0, 45, 122) !important]root
[color=rgb(184, 92, 0) !important]# 接着在/etc/dnsmasq.d/目录下新建一个文件,随意起个名字
[color=rgb(0, 45, 122) !important]vi[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]etc[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]dnsmqsq[color=rgb(51, 51, 51) !important].[color=rgb(0, 45, 122) !important]d[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]dns[color=rgb(51, 51, 51) !important].[color=rgb(0, 45, 122) !important]conf
[color=rgb(184, 92, 0) !important]# 指定你要映射的域名,例如,则将下面贴进dns.conf文件
[color=rgb(0, 45, 122) !important]address[color=rgb(0, 111, 224) !important]=[color=rgb(221, 17, 68) !important]&//172.17.0.4&
[color=rgb(184, 92, 0) !important]# 最后退出容器,重启启动容器时,通过-dns选项指定域名服务器
[color=teal !important]docker [color=rgb(0, 45, 122) !important]run[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]i[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]t[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-dns[color=rgb(0, 111, 224) !important] [color=rgb(0, 153, 153) !important]127.0.0.1[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-dns[color=rgb(0, 111, 224) !important] [color=rgb(0, 153, 153) !important]8.8.8.8[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]dev[color=rgb(0, 111, 224) !important]:[color=rgb(0, 45, 122) !important]base[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]bin[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]bash
[color=rgb(184, 92, 0) !important]# 一定要注意上面添加google的域名服务器8.8.8.8,否则你访问不了外网
[color=rgb(184, 92, 0) !important]# 进去Container后,启动dnsmasq,这样你就能够了
[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]etc[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]init[color=rgb(51, 51, 51) !important].[color=rgb(0, 45, 122) !important]d[color=rgb(0, 111, 224) !important]/[color=teal !important]dnsmasq start
第2个问题的解决方案就稍微麻烦些,起码我没有找到更好的解决方案,我是将boot2docker.iso文件重新制作一次来解决这个问题的:
[backcolor=rgb(238, 238, 238) !important][color=rgb(102, 102, 102) !important]
[color=rgb(102, 102, 102) !important]C
[color=rgb(170, 170, 170) !important]1
[color=rgb(170, 170, 170) !important]2
[color=rgb(170, 170, 170) !important]3
[color=rgb(170, 170, 170) !important]4
[color=rgb(170, 170, 170) !important]5
[color=rgb(170, 170, 170) !important]6
[color=rgb(170, 170, 170) !important]7
[color=rgb(170, 170, 170) !important]8
[color=rgb(170, 170, 170) !important]9
[color=rgb(170, 170, 170) !important]10
[color=rgb(170, 170, 170) !important]11
[color=rgb(170, 170, 170) !important]12
[color=rgb(170, 170, 170) !important]13
[color=rgb(170, 170, 170) !important]14
[color=rgb(170, 170, 170) !important]15
[color=rgb(170, 170, 170) !important]16
[color=rgb(170, 170, 170) !important]17
[color=rgb(170, 170, 170) !important]18
[color=rgb(170, 170, 170) !important]19
[color=rgb(170, 170, 170) !important]20
[color=rgb(170, 170, 170) !important]21
[color=rgb(170, 170, 170) !important]22
[color=rgb(170, 170, 170) !important]23
[color=rgb(170, 170, 170) !important]24
[color=rgb(170, 170, 170) !important]25
[color=rgb(170, 170, 170) !important]26
[color=rgb(170, 170, 170) !important]27
[color=rgb(170, 170, 170) !important]28
[color=rgb(170, 170, 170) !important]29
[color=rgb(170, 170, 170) !important]30
[color=rgb(170, 170, 170) !important]31
[color=rgb(170, 170, 170) !important]32
[color=rgb(170, 170, 170) !important]33
[color=rgb(170, 170, 170) !important]34
[color=rgb(170, 170, 170) !important]35
[color=rgb(170, 170, 170) !important]36
[color=rgb(170, 170, 170) !important]37
[color=rgb(170, 170, 170) !important]38
[color=rgb(170, 170, 170) !important]39
[color=rgb(170, 170, 170) !important]40
[color=rgb(170, 170, 170) !important]41
[color=rgb(170, 170, 170) !important]42
[color=rgb(184, 92, 0) !important]# 首先你需要将boot2docker.iso文件mount到一个目录下
[color=teal !important]hdiutil [color=rgb(0, 45, 122) !important]mount[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]~[color=rgb(0, 111, 224) !important]/[color=rgb(51, 51, 51) !important].[color=rgb(0, 45, 122) !important]boot2docker[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]boot2docker[color=rgb(51, 51, 51) !important].[color=rgb(0, 45, 122) !important]iso
[color=rgb(184, 92, 0) !important]# 系统会mount到/Volumes/boot2docker目录下,然后你最好将这下面的东西copy出来到一个另外的目录,这样我们好制作一张新的ISO
[color=rgb(0, 45, 122) !important]cp[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]r[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]Volumes[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]boot2docker[color=rgb(0, 111, 224) !important]/[color=rgb(0, 111, 224) !important]*[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]~[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]tmp[color=rgb(0, 111, 224) !important]/
[color=rgb(184, 92, 0) !important]# 接着我们修改以下文件
[color=rgb(0, 45, 122) !important]vi[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]~[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]tmp[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]boot[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]isolinux[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]isolinux[color=rgb(51, 51, 51) !important].[color=rgb(0, 45, 122) !important]cfg
[color=rgb(184, 92, 0) !important]# 将其中的以下这行修改:
[color=teal !important]append [color=rgb(0, 45, 122) !important]loglevel[color=rgb(0, 111, 224) !important]=[color=rgb(0, 153, 153) !important]3[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]user[color=rgb(0, 111, 224) !important]=[color=teal !important]docker [color=rgb(0, 45, 122) !important]console[color=rgb(0, 111, 224) !important]=[color=teal !important]ttyS0 [color=rgb(0, 45, 122) !important]console[color=rgb(0, 111, 224) !important]=[color=teal !important]tty0 [color=teal !important]nomodeset [color=teal !important]norestore [color=rgb(0, 45, 122) !important]base
[color=rgb(184, 92, 0) !important]# 修改为:(其实就是加了tz的启动参数),然后保存
[color=teal !important]append [color=rgb(0, 45, 122) !important]tz[color=rgb(0, 111, 224) !important]=[color=rgb(0, 45, 122) !important]CST[color=rgb(0, 111, 224) !important]-[color=rgb(0, 153, 153) !important]8[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]loglevel[color=rgb(0, 111, 224) !important]=[color=rgb(0, 153, 153) !important]3[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]user[color=rgb(0, 111, 224) !important]=[color=teal !important]docker [color=rgb(0, 45, 122) !important]console[color=rgb(0, 111, 224) !important]=[color=teal !important]ttyS0 [color=rgb(0, 45, 122) !important]console[color=rgb(0, 111, 224) !important]=[color=teal !important]tty0 [color=teal !important]nomodeset [color=teal !important]norestore [color=rgb(0, 45, 122) !important]base
[color=rgb(184, 92, 0) !important]# 接着你必须在ubuntu环境下重新制作ISO文件,你可以利用docker跑一个ubuntu,哈哈,假设你将boot2docker目录copy到了ubuntu的/src/目录下,那么接着这么做
[color=rgb(184, 92, 0) !important]# 安装xorriso命令
[color=rgb(0, 45, 122) !important]apt[color=rgb(0, 111, 224) !important]-[color=teal !important]get [color=teal !important]install [color=rgb(0, 45, 122) !important]xorriso
[color=rgb(184, 92, 0) !important]# 构建ISO映射
[color=rgb(0, 45, 122) !important]xorriso[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-as[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]mkisofs[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]J[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]R[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-V[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]boot2docker[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]no[color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]emul[color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]boot[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]boot[color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]load[color=rgb(0, 111, 224) !important]-size[color=rgb(0, 111, 224) !important] [color=rgb(0, 153, 153) !important]4[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]boot[color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]info[color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]table[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-b[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]boot[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]isolinux[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]isolinux[color=rgb(51, 51, 51) !important].[color=rgb(0, 45, 122) !important]bin[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-c[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]boot[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]isolinux[color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]boot[color=rgb(51, 51, 51) !important].[color=rgb(0, 45, 122) !important]cat[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]-[color=rgb(0, 45, 122) !important]o[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]boot2docker[color=rgb(51, 51, 51) !important].[color=rgb(0, 45, 122) !important]iso[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]/[color=rgb(0, 45, 122) !important]src[color=rgb(0, 111, 224) !important]/
[color=rgb(184, 92, 0) !important]# 这样就生成了/boot2docker.iso文件,最后你就可以替换到VM的启动ISO文件了,然后重启VM了
[color=teal !important]boot2docker [color=rgb(0, 45, 122) !important]restart
[color=rgb(184, 92, 0) !important]# 最后你必须设置你的VM为正确的时间,使用date -s 命令,最后用date命令查看,你就能看到CST时区的正确时间了
[color=teal !important]Sun Mar[color=rgb(0, 111, 224) !important] [color=rgb(0, 153, 153) !important]30[color=rgb(0, 111, 224) !important] [color=rgb(0, 153, 153) !important]00[color=rgb(0, 111, 224) !important]:[color=rgb(0, 153, 153) !important]27[color=rgb(0, 111, 224) !important]:[color=rgb(0, 153, 153) !important]13[color=rgb(0, 111, 224) !important] CST[color=rgb(0, 111, 224) !important] [color=rgb(0, 153, 153) !important]2014
[color=rgb(184, 92, 0) !important]# 对于你启动的container,你都必须重新设置TZ环境变量,否则即使VM是CST-8,你的container还是UCT +00:00的时间
[color=teal !important]export [color=rgb(0, 45, 122) !important]TZ[color=rgb(0, 111, 224) !important]=[color=rgb(221, 17, 68) !important]'CST-8'
第三个问题暂时无法解决(可能需要编辑底层的LXC配置文件)。
论坛徽章:349
docker的限制以及后续的一些想法
docker其实还是有一些限制的:
要求你的环境是Linux的,而且内核必须很新(&= 2.6.27 (29)),这其实是LXC本身的限制,和docker无关
docker的Container目前host是不能修改的,当然有解决方案(dnsmasq)
docker的Container也暂时无法指定静态IP
用docker作为开发环境甚至是生产环境其实还有很多地方值得尝试:
在团队内部构建本地的仓库,标准化所有的开发环境,使得团队的新人可以快速上手
在生产环境部署docker,这其实是PAAS的虚拟化和自动化的一种方式,利用LXC和Docker能够更便捷地实施PAAS
尝试用docker做分布式集群模拟和测试,成本会更加低廉,更加容器维护
Linux虚拟化技术
利用Linux容器实现可移植的应用部署
如何修改host
Building a Development With Docker
boot2docker的build
PAAS Under the Hood
论坛徽章:349
Kubernetes是Google开源的容器集群管理系统。它构建于docker技术之上,为容器化的应用提供资源调度、部署运行、服务发现、扩容缩容等整一套功能,本质上可看作是基于容器技术的mini-PaaS平台。本文旨在梳理Kubernetes的架构、概念及基本工作流,并且通过运行一个简单的示例应用来介绍如何使用Kubernetes。总体概览如下图所示是我初步阅读文档和源代码之后整理的总体概览,基本上可以从如下三个维度来认识Kubernetes。
论坛徽章:349
操作对象Kubernetes以RESTFul形式开放接口,用户可操作的REST对象有三个:pod:是Kubernetes最基本的部署调度单元,可以包含container,逻辑上表示某种应用的一个实例。比如一个web站点应用由前端、后端及数据库构建而成,这三个组件将运行在各自的容器中,那么我们可以创建包含三个container的pod。service:是pod的路由代理抽象,用于解决pod之间的服务发现问题。因为pod的运行状态可动态变化(比如切换机器了、缩容过程中被终止了等),所以访问端不能以写死IP的方式去访问该pod提供的服务。service的引入旨在保证pod的动态变化对访问端透明,访问端只需要知道service的地址,由service来提供代理。replicationController:是pod的复制抽象,用于解决pod的扩容缩容问题。通常,分布式应用为了性能或高可用性的考虑,需要复制多份资源,并且根据负载情况动态伸缩。通过replicationController,我们可以指定一个应用需要几份复制,Kubernetes将为每份复制创建一个pod,并且保证实际运行pod数量总是与该复制数量相等(例如,当前某个pod宕机时,自动创建新的pod来替换)。
可以看到,service和replicationController只是建立在pod之上的抽象,最终是要作用于pod的,那么它们如何跟pod联系起来呢?这就要引入label的概念:label其实很好理解,就是为pod加上可用于搜索或关联的一组key/value标签,而service和replicationController正是通过label来与pod关联的。如下图所示,有三个pod都有label为&app=backend&,创建service和replicationController时可以指定同样的label:&app=backend&,再通过label selector机制,就将它们与这三个pod关联起来了。例如,当有其他frontend pod访问该service时,自动会转发到其中的一个backend pod。
itpub.net All Right Reserved. 北京皓辰网域网络信息技术有限公司版权所有    
 北京市公安局海淀分局网监中心备案编号: 广播电视节目制作经营许可证:编号(京)字第1149号

我要回帖

更多关于 docker 管理工具 的文章

 

随机推荐