Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Docker for Java developers at JavaLand


Published on

Slides for the Docker for Java Developers workshop at JavaLand in 2017. It covers building and running containers. It also covers running GUI applications in Docker and using the Docker registry.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Docker for Java developers at JavaLand

  1. 1. Johan Janssen, Info Support, @johanjanssen42
  2. 2. To enable continuous delivery Quickly provision environments Run the same software local and in the cloud
  3. 3. Disk space efficiency Memory efficiency Speed Compatibility (run anywhere) Isolation Versioning Internet of Things (Raspberry Pi etc.)
  4. 4. docker run -i -t ubuntu:yakkety /bin/bash
  5. 5. DTAP environment Build environment Mainly running non-GUI applications Continuous delivery, testing etc. Development !
  6. 6. 
  7. 7. DevOps End users
  8. 8. Continuous delivery Continuous deployment
  9. 9. 1 2 3 4 6 7 8 9 5
  10. 10. Main directory GeneralBase Dockerfile SonarQube Dockerfile
  11. 11. FROM ubuntu:saucy RUN apt-get -y install software-properties- common RUN add-apt-repository ppa:webupd8team/java RUN apt-get update && apt-get -y upgrade RUN echo "oracle-java7-installer shared/accepted-oracle- license-v1-1 boolean true" | debconf-set-selections RUN apt-get -y install oracle-java7-installer ENV JAVA_HOME /usr/lib/jvm/java-7-oracle
  12. 12. Create the Dockerfile Build the containers: <optional>cd GeneralBase build -t GeneralBase . cd .. </optional>
  13. 13. FROM GeneralBase RUN apt-get install -y wget unzip RUN wget RUN unzip -d /opt RUN rm EXPOSE 9000 EXPOSE 9092 CMD ["/opt/sonarqube-4.2/bin/linux-x86-64/", "console", "/bin/bash"]
  14. 14. Create the Dockerfile Build the containers: cd SonarQube build -t SonarQube .
  15. 15. Start the container run -p 9000:9000 –p 9092:9092 -d SonarQube
  16. 16. # ps –a CONTAINER ID: ecbecf77461b CREATED: 32 minutes ago STATUS: Up 32 minutes PORTS:>9000/tcp,>9092/tcp
  17. 17. Start / stop / restart docker [start/stop/restart] containerid Follow SystemOut and SystemErr docker logs -f containerid
  18. 18. GeneralBase AppServerBase Environment D Environment T Environment A Environment P Jenkins JenkinsDataContainer Sonar Gitblit Nexus
  19. 19. In the same container as the application In a data container / data volume On the host
  20. 20. Dockerfile ENV JENKINS_HOME /var/JenkinsData Docker commands run -v /var/JenkinsData –name JenkinsDataContainer ubuntu:saucy true run -p 8080:8080 --volumes-from JenkinsDataContainer -d Jenkins
  21. 21. # images --tree └─ 179.9 MB Tags: ubuntu:saucy └─253.6 MB └─741.8 MB Tags: GeneralBase:latest └─763.6 MB Tags: AppServerBase:latest … ├─763.6 MB Tags: EnvironmentP:latest └─865.6 MB Tags: Nexus:latest └─808.3 MB Tags: Gitblit:latest └─901.5 MB Tags: Sonar:latest └─805.4 MB Tags: Jenkins:latest
  22. 22. real 4m11.729s user 0m3.329s sys 0m10.054s
  23. 23. Creating the Docker registry docker run -p 5000:5000 registry
  24. 24. Modify container Commit commit 064f New containerid -> ff7e Push push
  25. 25. Pull pull test-version-0.2 Run run -i -t ff7e /bin/bash
  26. 26. docker images -tree └─153b 194.2 MB test-version-0.1:latest docker pull version-0.2 ff7e: Download complete 153b: Download complete docker images -tree └─153b 194.2 MB test-version-0.1:latest └─ff7e 194.2 MB test-version-0.2:latest
  27. 27. 
  28. 28. FROM java:8-jdk RUN wget …/ RUN chmod +x netbeans*.sh RUN sh netbeans*.sh --silent CMD /usr/local/netbeans-8.0.2/bin/netbeans
  29. 29. Docker run command: -v $PWD/workspace:/workspace
  30. 30. Workspace Plugins Application in application server Maven repo Configuration Entire home folder??
  31. 31. “Eclipse Che is an IDE and developer workspace server that allows anyone to contribute to a project without having to install software.”
  32. 32. Team Frodo image Base image Team Bilbo image
  33. 33. • App Gimli • App Elrond Team Frodo • App Elrond Team Bilbo • App Radagast Team Galadriel App means application server etc.
  34. 34. Where do we place the Elrond App? • App Gimli • App Elrond Team Frodo • App Elrond Team Bilbo • App Radagast Team Galadriel
  35. 35. Tomcat Image Gimli Elrond Radagast
  36. 36. Fedora Image Development environment
  37. 37. Define and run multi container Docker applications Using a Compose file Link containers ‘docker-compose up’ to start the containers
  38. 38. TomcatGimli DockerFile TomcatElrond DockerFile TomcatRadagast Dockerfile DevEnv Dockerfile docker-compose.yml
  39. 39. tomcatgimli: build: TomcatGimli tomcatelrond: build: TomcatElrond tomcatradagast: build: TomcatRadagast developmentenvironment: build: DevEnv ports: - "3389:3389" links: - tomcatgimli:gimli # Makes gimli available on # http://gimli:8080 - tomcatelrond:elrond - tomcatradagast:radagast
  40. 40. Use docker-compose.override.yml Put all the configuration in one container Create small containers with configuration per environment that inherit the application container Commandline arguments
  41. 41. Use a (private) Docker registry Keep environmental settings separate Use Jenkins to manage everything Do not add extra functionality like OpenSSH Think about topics such as security, monitoring and logging Inherit and/or compose containers Separate concerns in separate containers
  42. 42. @johanjanssen42