Docker生产环境实践指南


技术栈:
1. 构建系统
2. 镜像仓库
3. 宿主机管理
4. 配置管理
5. 部署
6. 编排
7. 日志
8. 监控

镜像:
1. 如果用户像往常一样运行包安装命令,这些永远也用不上的缓存包文件将会永远地成为镜像的一部分。不过,如果用户在同一条安装命令中删除它们,这些文件就会像从未存在过一样。
RUN xxxxxxxxxxxxxxxxxxx \
&& xxxxxxxxxxxxxxxxxxx \
&& rm -f ......
  1. 通过环境变量将配置传递给容器内部
  2. 当用户需要包装一个无法通过环境变量配置的服务时,使用模板文件,使用一个入口点脚本,获取环境变量并在文件系统上生成配置文件,然后调用实际进程,该进程将在启动时读取那些新生成的配置文件。
    让镜像在Docker变化时对自身进行重新配置,docker-gen这个工具在Docker提供的容器信息基础上,使用提供的模板来生成配置文件,它动作的方式是它会监视或轮询Docker进程以获取容器内的变化(添加、删除等),并在发生变化时从模板重新生成配置文件。 https://github.com/jwilder/docker-gen
  3. 将日志文件链接到标准输出,如在nginx中配置
    access_log /var/log/nginx/access.log main;
    在Dockerfile中,将/dev/stdout链接到该文件
    RUN ln -sf /dev/stdout /var/log/nginx/access.log

私有仓库
1. 加固(SSL、认证)https://docker.github.io/registry/deploying/
基于令牌的认证方式是唯一可供选择的安全选项
  1. 最小化Docker镜像 docker-squash https://github.com/jwilder/docker-squash

在生产环境中使用Docker的一些标准:
1. 在一个构建系统中构建所有镜像
2. 不要使用或禁止使用非标准做法
3. 使用标准基础镜像
4. 使用Docker进行集成测试

配置
由于配置管理擅长的是装配宿主机,因而它们在新的容器化的世界里并没有多少用武之地。它们的作用也从负责配置整个系统转变成只是负责配置运行这些应用服务的基础设施,这包括从Docker宿主机的配置到Mesos集群的搭建等。
Chef
https://github.com/chef-cookbooks/docker
https://github.com/chef-boneyard/chef-container
Ansible
https://github.com/angstwad/docker.ubuntu
http://docs.ansible.com/ansible/docker_module.html
Salt Stack
Puppet
https://forge.puppet.com/garethr/docker/readme

存储引擎
https://labs.ctl.io/
查看镜像分层的工具 Image Layers https://imagelayers.io/
AUFS
DeviceMapper 预分配thin provisioning
https://www.kernel.org/doc/Doc ... pper/
在生产环境下应用devicemapper引擎时请记得一定要设置成使用真实的块设备来存储数据和元数据设备。
https://github.com/docker/dock ... apper
BTRFS
https://btrfs.wiki.kernel.org/index.php/Main_Page
OverlayFS
https://git.kernel.org/cgit/li ... s.txt
VFS 不提供写时复制,不太适用于生产环境,但依旧算是挂载Docker卷的一个不错的解决方案,,在FreeBSD这样的非Linux平台上运行

网络
零配置网络zeroconf http://zeroconf.org/
多主机的容器间通信
大使模式(ambassador pattern) https://docs.docker.com/engine ... king/
开放虚拟交换机(OVS)和GRE隧道: 用OVS创建一个网桥来取代默认的docker0,然后在内网的宿主机之间创建一个安全的GRE隧道。
https://goldmann.pl/blog/2014/ ... osts/
libnetwork https://github.com/docker/libnetwork
swarm https://github.com/docker/swarm
共享网络命名空间 
kubernetes http://kubernetes.io
pod https://github.com/GoogleCloud ... ds.md
启动容器时带上参数--net=container:NAME_or_ID,就可以将该容器加入到NAME_or_ID容器的“基础”网络命名空间
https://speakerdeck.com/gyre00 ... iners
Docker允许用户在创建容器的时候和它的宿主机共享网络命名空间,该宿主机本身在PID 1进程的命名空间里运行它的网络栈,对于容器来说它们可以很轻松地加入宿主机的网络命名空间里,即:容器的网络栈和宿主机之间是共享的。--net=host
IPv6 当前Docker已经加入了对IPv6的支持 http://docs.docker.com/engine/ ... king/
pipework
https://github.com/jpetazzo/pipework
pipework镜像 https://hub.docker.com/r/dreamcat4/pipework/
weave
https://github.com/weaveworks/weave
安全增强 http://www.weave.works/weave-net-cryptography-faq/
可视化 weave scope 
https://github.com/weaveworks/scope
http://thenewstack.io/how-to-d ... orks/
快速网络路径 http://www.weave.works/weave-fast-datapath/
Docker插件系统
https://blog.docker.com/2015/0 ... gins/
把weave当做Docker的插件使用 http://www.weave.works/weave-a ... ugin/
flannel
https://github.com/coreos/flannel
VXLAN https://en.wikipedia.org/wiki/ ... e_LAN
etcd https://github.com/coreos/etcd
calico (3层解决方案) 原生的IPv6支持,分布式BGP路由
http://www.projectcalico.org
ClusterHQ powerstrip https://github.com/ClusterHQ/powerstrip

调度
Mesos+marathon
优势资源公平算法 https://www.cs.berkeley.edu/~alig/papers/drf.pdf
Kubernetes
OpenShift (Red Hat) https://www.openshift.com/open ... more/
Atomic项目 http://www.projectatomic.io
Red Hat容器安全标准 https://securityblog.redhat.co ... arts/

服务发现
最低要求:服务注册/服务声明、服务查找/服务发现
服务注册的两种实现方式:
1. 把服务注册的模块直接嵌入到应用服务的源代码里
2. 使用一个伙伴进程(或者说是协同进程)来帮忙处理注册的任务
DNS
SkyDNS 
https://github.com/skynetservices/skydns
SkyDNS docker镜像 https://hub.docker.com/r/skynetservices/skydns/
skydock (SkyDNS集成到Docker的方案,目前只能用在一台Docker宿主机上) https://github.com/crosbymichael/skydock
weave-dns (允许跨多台Docker宿主机,但必须在专有的weave覆盖网络上使用)
https://github.com/weaveworks/ ... vedns

Zookeeper
znode
Apache Curator(zookeeper客户端库) http://curator.apache.orgX17X 入门文档 http://tomaszdziurko.pl/2014/0 ... cing/

etcd
生产环境集群设置方案 https://coreos.com/os/docs/lat ... .html
安全模型 https://github.com/coreos/etcd ... ty.md
Docker Service Discovery Using Etcd and Haproxy http://jasonwilder.com/blog/20 ... very/

consul 分布式键值存储、分布式监控工具、DNS服务器
https://www.consul.io/docs/index.html
serf https://www.serfdom.io
Web UI https://github.com/hashicorp/c ... ME.md
registrator https://github.com/gliderlabs/registrator
镜像 https://registry.hub.docker.co ... ator/

Eureka
https://github.com/Netflix/eureka
https://github.com/Netflix/eur ... rview
Netflix http://techblog.netflix.com
http://netflix.github.io

Smartstack 技术无关性,不需要用户编写任何额外的应用代码,可被部署到祼机、虚拟机或Docker容器里
包含zookeeper、haproxy以及
Nerve 监控机器和服务的健康状况 https://github.com/airbnb/nerve
Synapse 服务发现 https://github.com/airbnb/synapse

nsqlookupd 在大规模基础设施里运行分布式消息队列的解决方案
http://nsq.io/components/nsqlookupd.html
http://nsq.io/components/nsqd.html

日志
在其它容器一侧收集日志
docker run -v /logs --name redis registry/redis
docker run -d --volumes-from redis --name log_collector registry/logcollector

监控
Datadog https://www.datadoghq.com/blog ... adog/
Docker Python API docker-py https://github.com/docker/docker-py
Docker 远程API https://docs.docker.com/refere ... _api/
Docker集群管理系统Shipyard https://github.com/shipyard/shipyard
docker ps 
docker stats
 

posted on 2016-10-31 16:55  生活费  阅读(2660)  评论(0编辑  收藏  举报

导航