Build service with_docker_in_90mins

Download Build service with_docker_in_90mins

Post on 23-Aug-2014

386 views

Category:

Internet

1 download

Embed Size (px)

DESCRIPTION

Learn how to build web service using docker, it is intermediate knowledge of docker. CodingWithMe style for 90 minutes

TRANSCRIPT

<ul><li> Larry cai </li> <li> Precondition You need finish/understand the basic docker knowledge in http://www.slideshare.net/larrycai/learn-docker-in-90-minutes What is docker Command : pull/run/images/ps .. Interactive and daemon mode Build with Dockerfile Build Service with Docker in 90 minutes2 08/14/14 </li> <li> Agenda Docker Revisit Exercise 1: Manage data in container (-v) Exercise 2: Manage data in container from another Exercise 3: Link containers (--name/-- link) Exercise 4: Remote API Exercise 5: Docker in Docker Exercise 6: Build service together (haproxy+2 tomcat) Build Service with Docker in 90 minutes3 08/14/14 Docker HostDocker Host HAProxy (Load Balancer) Tomcat (web1) Tomcat (web1) 808080 8080 Web Service Tomcat (web2) Tomcat (web2) 8080 ClientClient </li> <li> Environment Preparation Boot2docker Installer (27M) Contains latest docker already, fast Container persistence via disk automount on/var/lib/docker Add proxy /var/lib/boot2docker/profile if needed $ sudo vi /var/lib/boot2docker/profile export http_proxy= $ sudo /etc/init.d/docker restart $ docker -v User/Passwd: docker/tcuser Build Service with Docker in 90 minutes4 08/14/14 http://boot2docker.io/ </li> <li> Docker Revisit Docker is an open-source engine that automates the deployment of any application as a lightweight, portable, self-sufficient container that will run virtually anywhere. Build Service with Docker in 90 minutes5 08/14/14 Based on LXC (Linux Container), easy to use. Similar to VM as end- user with different features </li> <li> Manage Data in Container Container as a Service and Data needs persistency Load balancer,App, Database, Data storage Share data from host by mount a Host Directory as a DataVolume VOLUME [ /var/data ] # in Dockerfile -v host:guest # in docker run Share data from another Data-only container --volumes-from data-container Backup/Restore Data-only container Build Service with Docker in 90 minutes6 08/14/14 http://docs.docker.com/userguide/dockervolumes/ Img source from: http://centricconsulting.com/it-shops-will-leverage-their-knowledge- </li> <li> Exercise 1: Manage data in tomcat run larrycai/tomcat without volume $ docker run P d larrycai/tomcat $ docker logs Share the local directory into it $ docker run v /tmp/webapps:/var/lib/tomcat7/webapps/ P d larrycai/tomcat Download sample.war http://192.168.59.103:xxx/sample Build Service with Docker in 90 minutes7 08/14/14 code https://github.com/larrycai/docker-tomcat sample.war https://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war </li> <li> Exercise 2: Data container for tomcat 1. Create data container (Tips: use e https_proxy:) $ docker run v /tmp/webapps:/var/lib/tomcat7/webapps -name webfarm jamtur01/fetcher https://tomcat.apache.org/tomcat- 7.0-doc/appdev/sample/sample.war 2. Share data from another container $ docker run -volumes-from webfarm P d larrycai/tomcat 3. Try to download new one Calendar.war to put into /tmp/wepapps Build Service with Docker in 90 minutes8 08/14/14 Code https://github.com/jamtur01/dockerbook-code/blob/master/code/6/tomcat/fetcher/Dockerfile Calendar.war https://gwt-examples.googlecode.com/files/Calendar.war </li> <li> Link the containers in docker Docker container has the same private network Name the container and Link them to provide the service outside and hide internal port/network ! Name the container docker run --name postgresql92 postgresql Link container to the another container --link name:alias docker --link postgresql92:db app Build Service with Docker in 90 minutes9 08/14/14 http://docs.docker.com/userguide/dockerlinks/ Img source from http://lethain.com/introduction-to-architecting-systems-for-scale </li> <li> Exercise 3: Link tomcat with haproxy Start tomcat with name web $ docker run -name tomcat d larrycai/tomcat Start another node with link alias $ docker run -it --link tomcat:web ubuntu bash Check environment and access it # env # check environment # cat /etc/hosts # check host # curl web:8080 Create another tomcat and Add HAProxy container $ docker run -name tomcat d larrycai/tomcat $ docker run -name tomcat2 d larrycai/tomcat $ docker run -link tomcat:back1 -link tomcat2:back2 it P larrycai/haproxy bash # export CONFIG=/etc/haproxy/haproxy.cfg # echo " server back1 ${BACK1_PORT_8080_TCP_ADDR}:8080 maxconn 32" &gt;&gt; $CONFIG # echo " server back2 ${BACK2_PORT_8080_TCP_ADDR}:8080 maxconn 32" &gt;&gt; $CONFIG # haproxy -f /etc/haproxy/haproxy.cfg # ^P^Q Access 80/8080 port Build Service with Docker in 90 minutes10 08/14/14 </li> <li> Docker API Docker client/server is communicated via Remote API Official docker port is 2375 (since 1.0) API tends to be REST Build Service with Docker in 90 minutes11 08/14/14 https://docs.docker.com/reference/api/docker_remote_api/ Img source from http://blog.arungupta.me/2014/07/getting- started-with-docker/ </li> <li> Exercise 4: Remote API Top of the container API: GET /containers/(id)/top Docker command: $ docker top List all images API: GET /images/json Docker command: $ docker images Try to find your favorite language for the docker remote API to play with. https://docs.docker.com/reference/api/remote_api_client_libraries/ Build Service with Docker in 90 minutes12 08/14/14 </li> <li> Docker in Docker Docker is client/Daemon via REMOTE API Docker in Docker can make environment much clean Docker Host only environment All applications are in docker container Easy to deployment Docker in Docker means install Docker Client into Container https://get.docker.io/builds/Linux/x86_64/docker-latest Build Service with Docker in 90 minutes13 08/14/14 </li> <li> Exercise 5: Docker in Docker Install docker client in docker container Run docker command inside !! $ docker run it -v /var/run/docker.sock:/docker.sock larrycai/docker bash # docker images Point to Docker Host &amp; Pass data inside # docker H unix:///docker.sock images or # export DOCKER_HOST=unix:///docker.sock # docker images Build Service with Docker in 90 minutes14 08/14/14 </li> <li> Exercise 6: Build Service Together Do it all Show the help Run the 2 tomcat container &amp; Run the one haproxy container over it. Show the generated port $ docker run larrycai/craft Build Service with Docker in 90 minutes15 08/14/14 Docker HostDocker Host HAProxy (Load Balancer) Tomcat (web1) Tomcat (web1) 808080 8080 Web Service Tomcat (web2) Tomcat (web2) 8080 ClientClient Craft (controll) https://github.com/larrycai/docker-images/tree/master/craft /demo.sh/demo.sh </li> <li> Recommend reading The Docker Book http://dockerbook.com Docker Docs https://docs.docker.com/ Build Service with Docker in 90 minutes16 08/14/14 </li> </ul>