Share
Embed
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
41 slides
-
Deploy a Java 8 webapp With Docker and Google
Cloud Pla1orm -
David Gageot hAp://javabien.net
@dgageot 2014 Developer Expert Cloud Platform -
What for? Different Operating System Different CPU Architecture
Works on my machine! Work with multiples versions in // Move application to a different server … -
Google and Containers “ Everything at Google,
from Search to Gmail, is packaged and run in a Linux container. Each week we launch more than 2 billion container instances across our global data centers, and the power of containers has enabled both more reliable services and higher, more-‐efficient scalability. “ http://googlecloudplatform.blogspot.fr/2014/06/an-update-on-container-support-on-google-cloud-platform.html -
Use an exisMng container $ docker run -‐i -‐t ubuntu:14.04
/bin/bash $ uname -‐a $ ls -‐als / -
Fun with the Container $ docker run -‐i -‐t ubuntu:14.04
/bin/bash $ sudo rm -‐Rf /etc $ ls /etc $ docker run -‐i -‐t ubuntu:14.04 /bin/bash $ ls -‐als / $ exit -
What’s an applicaMon? Binaries and Libraries (JDK) Application (Jars) Server
OS (Linux) Kernel Boot Time Size Disk & RAM State (Memory, Written Data) Common Files (/etc, /bin,…) -
And in a VM? Hypervisor Guest OS (Debian) Boot
Time Size Disk & RAM Bins and Libs (JDK) Application (Jars) Server Host OS (Linux) Kernel Guest OS (Debian) Bins and Libs (JDK) Application (Jars) State State Host’s Common Files (/etc, /bin,…) Guest’s Common Files Guest’s Common Files -
One Kernel to rule them all Bins and Libs (JDK)
Application (Jars) Server Host OS (Linux Only) Kernel Application (Jars) State State Host’s Common File (/etc, /bin,…) Guest’s Common Files Bins and Libs (JDK) Guest’s Common Files Hypervisor Guest OS (Debian) Bins and Libs (JDK) Application (Jars) Server Host OS (Linux) Kernel Guest OS (Debian) Bins and Libs (JDK) Application (Jars) State State Host’s Common Files (/etc, /bin,…) Guest’s Common Files Guest’s Common Files VMs -
Share the Read only files Binaries and Libraries (JDK) Application
(Jars) Server Host OS (Linux Only) Kernel Application (Jars) State State Host’s Common Files (/etc, /bin,…) Guest’s Common Files VMs Hypervisor Guest OS (Debian) Bins and Libs (JDK) Application (Jars) Server Host OS (Linux) Kernel Guest OS (Debian) Bins and Libs (JDK) Application (Jars) State State Host’s Common Files (/etc, /bin,…) Guest’s Common Files Guest’s Common Files -
It’s all about files Server Host OS (Linux Only) Kernel
State State Common Files, Bins and Libraries (/etc, /bin,…) VMs Hypervisor Guest OS (Debian) Bins and Libs (JDK) Application (Jars) Server Host OS (Linux) Kernel Guest OS (Debian) Bins and Libs (JDK) Application (Jars) State State Host’s Common Files (/etc, /bin,…) Guest’s Common Files Guest’s Common Files Application (Jars) Application (Jars) -
Share the ApplicaMon VMs Hypervisor Guest OS (Debian) Bins and
Libs (JDK) Application (Jars) Server Host OS (Linux) Kernel Guest OS (Debian) Bins and Libs (JDK) Application (Jars) State State Host’s Common Files (/etc, /bin,…) Guest’s Common Files Guest’s Common Files Server Host OS (Linux Only) Kernel State State Common Files, Bins and Libraries (/etc, /bin,…) Application (Jars) -
As fast as “naMve” apps Boot Time Size
Disk & RAM Server Host OS (Linux Only) Kernel State State Common Files, Bins and Libraries (/etc, /bin,…) Application (Jars) -
Our target Webapp Application Server Debian VM on Google Compute
Engine Kernel State Git, Maven, Java 8 Ubuntu State Docker It’s a Container -
Describe your applicaMon with a Dockerfile from base
maintainer David Gageot <[email protected]> # Install prerequisites run apt-‐get update run apt-‐get install -‐y software-‐properties-‐common # Install java8 run add-‐apt-‐repository -‐y ppa:webupd8team/java run apt-‐get update run echo oracle-‐java8-‐installer shared/accepted-‐oracle-‐license-‐v1-‐1 select true | sudo /usr/bin/debconf-‐set-‐selections run apt-‐get install -‐y oracle-‐java8-‐installer # Install tools run apt-‐get install -‐y git maven # Clone project run git clone https://github.com/dgageot/helloworld.git # Build project run cd helloworld && mvn verify dependency:copy-‐dependencies # Expose the http port expose 8080 workdir helloworld This one is hosted on GitHub ie ubuntu -
Dockerfile Build the Container Each command creates a new
read-‐only layer $ docker build -‐t dgageot/helloworld github.com/dgageot/helloworld Application Sources Git Ubuntu Java 8 Maven Application Jars -
Fun with the Container Try to build twice and
see the cache being used $ docker build -‐t dgageot/helloworld github.com/dgageot/helloworld $ docker build -‐t dgageot/helloworld github.com/dgageot/helloworld Uploading context 190.5 kB Uploading context Step 0 : from base ---> b750fe79269d Step 1 : maintainer David Gageot <[email protected]> ---> Using cache ---> c50bcc57f807 Step 2 : run apt-get update ---> Using cache ---> 0a3783337ecb Step 3 : run apt-get install -y software-properties-common ---> Using cache ---> 5399953b8138 Step 4 : run add-apt-repository -y ppa:webupd8team/java ………. -
Fun with the Container Run java from the container
Java installed on host: $ java -‐version Java installed on the container: $ docker run dgageot/helloworld java -‐version -
Fun with the Container Run the java 8 webapp
$ docker run -‐p 80:8080 -‐t -‐i dgageot/helloworld \ java -‐jar target/hello.jar or $ docker run -‐p 80:8080 -‐t -‐d dgageot/helloworld \ java -‐jar target/hello.jar $ docker ps -
Deploy on Compute Engine Create a server instance $
gcutil \ -‐-‐service_version=v1 \ -‐-‐project=numeric-‐scope-‐568 \ addinstance hello \ -‐-‐zone=europe-‐west1-‐b \ -‐-‐machine_type=n1-‐standard-‐1 \ -‐-‐tags=http-‐server \ -‐-‐image="https://www.googleapis.com/compute/v1/projects/ debian-‐cloud/global/images/backports-‐debian-‐7-‐wheezy-‐v20140415" -
Ssh into the VM $ gcutil \ -‐-‐service_version=v1
\ -‐-‐project=numeric-‐scope-‐568 \ ssh \ -‐-‐zone=europe-‐west1-‐b \ hello -
Build and Run the container Same thing as on localhost.
That’s the whole point! -
Use a container image instead of build from Dockerfile
Need to publish the image (public or private) -
Describe the setup $ cat containers.yaml version: v1beta1
containers: -‐ name: helloworld image: dgageot/helloworld command: ['java', '-‐jar', 'target/hello.jar'] ports: -‐ name: http hostPort: 80 containerPort: 8080 -
Deploy gcloud compute instances create jug \
-‐-‐image projects/google-‐containers/global/images/container-‐vm-‐ v20140522 \ -‐-‐metadata-‐from-‐file google-‐container-‐manifest=containers.yaml \ -‐-‐zone europe-‐west1-‐b \ -‐-‐machine-‐type n1-‐standard-‐1 \ -‐-‐tags=http-‐server -
The future of Docker On Google Cloud Pla1orm Support
of Docker images on App Engine Through managed VMs Kubernetes Kubernetes builds on top of Docker to construct a clustered container scheduling service. cAdvisor Fine-‐grain statistics on resource usage for containers Eric Brewer, VP of Infrastructure Google Nominated to Docker's Governance Committee -
Q&A Enfin nous déploierons ce site web sur la Google
Cloud Platform en utilisant Compute Engine avec du load balancing. Ce déploiement sera aussi l'occasion de voir comment faire communiquer plusieurs Dockers entre eux.