700 likes | 714 Views
Learn how to run Java applications with Docker on the Raspberry Pi and other platforms. Explore the potential of IoT, Docker compatibility, and the benefits of using Docker for continuous delivery.
E N D
Run Java applications with Docker on the Raspberry Pi and other platforms Johan Janssen, Info Support
Content • Internet of Things • Docker and Java on a Raspberry Pi • Jenkins • Questions
Potential market • Huge and still growing • Not stable yet, lots of innovation • Cool new technologies • Suitable for Java!
Developments outside the IoT • Continuous Delivery • Virtual machines • Provisioning (Chef, Puppet, Vagrant …) • Version control / infrastructure as code • Isolation • Updating and synchronizing environments
Why Docker • To enable continuous delivery • Quickly provision environments • Easy to roll forward • Security • For instance to run ‘untrusted’ applications like a Dropbox client • Alternative for virtual machines • On top of virtual machines
Docker vs Virtual Machines • Disk space efficiency • Memory efficiency • Speed • Compatibility (run anywhere) • Isolation • Versioning • Internet of Things (Raspberry Pi etc.)
Docker vs provisioning tools • Simple general commands • No Domain Specific Language (DSL) • Configuration with operating system commands
Docker activity • Since March 2013 • More than 460 570 contributors • Downloaded 2.75 13 million times • More than 14000 30000 Dockerized apps • More than 90 user groups, DockerCon(Europe) • Support from Google, VMWare, RackSpace, Red Hat, IBM, Microsoft etcetera
My first Docker container • Docker on Ubuntu 14.04 apt-get install docker.io docker.io run -i -t ubuntu:saucy/bin/bash
My first Pi Dockercontainer • Docker on the Raspberry Pi dockerrun -i–t resin/rpi-raspbian/bin/bash
Raspberry installation • Download Arch Linux http://downloads.raspberrypi.org/arch_latest • unzip ArchLinuxARM-2014.06-rpi.img.zip • Find SD card: sudofdisk -l • sudoddbs=1M if=ArchLinuxARM-2014.06-rpi.img of=/dev/sdX • Change partitions (optional) • Put the SD card in the Raspberry Pi and boot username and password are both ‘root’
Raspberry installation • Update repositories pacman –Syy • Optional update al packages: pacman-Syu • Install Docker pacman-S docker
Raspberry installation • Start Dockerservice systemctlstart docker • Auto start Docker service on boot systemctlenable docker • Reboot
Configure static IP address • cp/etc/netctl/examples/ethernet-static /etc/netctl/static • Edit /etc/netctl/static Description='A basic static ethernet connection' Interface=eth0 Connection=ethernet AutoWired=yes IP=static Address=('192.168.1.3/24') Gateway='192.168.1.1' DNS=('192.168.1.1')
Static IP address • Enable static ip netctlenable static • Disable static ip mv /etc/netctl/static /etc/netctl/examples/
Tomcat Dockerfile FROM resin/rpi-raspbian RUN apt-get update RUN apt-get install -y openjdk-7-jre-headless wget RUN wget -O /tmp/tomcat8.tar.gz http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.9/bin/apache-tomcat-8.0.9.tar.gz RUN (cd /opt && tar zxf /tmp/tomcat8.tar.gz) RUN (mv /opt/apache-tomcat* /opt/tomcat) ENV JAVA_HOME /usr/lib/jvm/java-1.7.0-openjdk-armhf RUN rm -rf /opt/tomcat/webapps/docs /opt/tomcat/webapps/examples /opt/tomcat/webapps/host-manager /opt/tomcat/webapps/manager EXPOSE 8080 CMD ["/opt/tomcat/bin/catalina.sh", "run"]
Tomcat Dockerfile explained FROM resin/rpi-raspbian RUN apt-get install -y openjdk-7-jre-headless wget ENV JAVA_HOME /usr/lib/jvm/java-1.7.0-openjdk-armhf EXPOSE 8080 CMD ["/opt/tomcat/bin/catalina.sh", "run"]
TomcatExtraDockerfile FROM tomcat ADD DockerPiExample.war /opt/tomcat/webapps/
Directory structure • Main directory • BuildAndRunScript.sh • Tomcat • Dockerfile • TomcatExtra • Dockerfile • DockerPiExample.war
Build • Create the Dockerfiles • Build the containers cd Tomcat (optional) dockerbuild -t tomcat . (optional) cd .. (optional) cd TomcatExtra docker build -t tomcatextra.
Run • Start the container dockerrun -p 8080:8080 -d tomcatextra
Hyper Text Coffee Pot Control Protocol • April Fools prank • It might become real
Controlling containers • Start / stop / restart docker [start/stop/restart] containerid • Follow SystemOut and SystemErr docker logs -f containerid
Controlling containers • Show (running) containers dockerps –a • Show processes running in container dockerdiff containerid • Show changes in the container dockertop containerid
Controlling containers • Stop all containers docker.io stop $(docker.io ps -a -q) • Remove all containers docker.io rm $(docker.io ps -a -q) • Remove all images docker.io rmi $(docker.io images -q)
Docker registry • Creating the Docker registry docker run -p 5000:5000 registry