设为首页 收藏本站
查看: 678|回复: 0

[经验分享] docker use case

[复制链接]

尚未签到

发表于 2015-10-13 10:15:52 | 显示全部楼层 |阅读模式






[size=1.5em]http://www.wouterdanes.net/2014/04/11/continuous-integration-using-docker-maven-and-jenkins.html



Docker



Docker is a tool allows you to run multiple processes in their own containers on a machine without the overhead of virtual machines. It does give process
separation and to the processes it looks like they're running in their own linux environment. Docker was created in Go and is basically an interface to Linux
Containers (LXC), a feature of the linux kernel that was introduced in the 3.8 release.

Docker works well under Ubuntu and Red Hat is working to make it enterprise
ready for RHEL.

Docker allows you to specify containers using Dockerfiles. These can be compared to Vagrantfiles that are used to provision
virtual machines. These docker files can be composed of other docker files, creating a sort of inheritance / composition of containers.


Creating an Integration Server Using Docker



I created a sample project on Github that shows how you can run integration tests on a sample Hippo project using docker. If you have Vagrant,
you can see the Jenkins server in action with a simple vagrant up from the root of the project. Using the
composition command in the Dockerfiles (FROM), I've built an oracle jdk 7 image that is used as the base of a tomcat image. I then use that tomcat image as the base for my integration environments. The Dockerfile for the integration image resides in the root
of the project and is as follows:

FROM wouterd/tomcat
MAINTAINER Wouter Danes "https://github.com/wouterd"
ADD myhippoproject.tar.gz /tmp/app-distribution/
RUN for i in $(ls /tmp/app-distribution/) ; do mkdir -p /var/lib/tomcat6/${i} && cp -f /tmp/app-distribution/${i}/* /var/lib/tomcat6/${i}/ ; done


The wouterd/tomcat image is built as follows:

FROM        wouterd/oracle-jre7
VOLUME      ["/var/log/tomcat6"]
MAINTAINER  Wouter Danes "https://github.com/wouterd"
RUN         apt-get install -y tomcat6
CMD         JAVA_HOME=/usr/lib/jvm/java-7-oracle CATALINA_BASE=/var/lib/tomcat6 CATALINA_HOME=/usr/share/tomcat6 /usr/share/tomcat6/bin/catalina.sh run
EXPOSE      8080


The wouterd/oracle-jre7 has some magic to install jdk 7 from oracle on a clean ubuntu VM. The code for this container and the two above is in the docker-images directory in the Github project. The wouterd/tomcat image does the following:


  • FROM wouterd/oracle-jre7 takes the container wouterd/oracle-jre7 (a container with Ubuntu + oracle
    java7 installed)
  • VOLUME ["/var/log/tomcat6"] tells the container to expose that path to the outside world. Docker
    actually "physically" places this path outside the container so that other containers can also reach it. Further down I will show why this is great. (Sneak peak: syslog deprecated?)
  • RUN apt-get install -y tomcat6 installs tomcat6 using the ubuntu repository
  • CMD [some bash] sets the command that gets executed when this container is run, setting two environment
    variables and starting catalina.sh
  • EXPOSE 8080 tells docker to expose port 8080 in the container to the host system.


The docker container that gets built during the integration test simply does two things:


  • Takes the wouterd/tomcat container
  • ADD [file] [destination] copies the tar.gz with the distribution from the maven project to a
    temporary folder and extracts it if it's a tar.
  • The RUN line is a convoluted way to copy the contents of the tar over the TOMCAT_HOME directory,
    for some reason simply adding the tar to the TOMCAT_HOME folder didn't let it extract properly. It would
    probably work if TOMCAT_HOME was just empty.
  • It inherits the CMD directive from the wouterd/tomcat container, so if you "run" the integration
    container using docker run, it will start up tomcat and start deploying the distribution.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-126176-1-1.html 上篇帖子: DOCKER INSTALL 下篇帖子: Docker 101:介绍与入门体验
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表