Vagrant or Docker for Java dev
environment?
Engineering Communities
22 October 2015
Orest Ivasiv
Software engineer, Softserve
Docker hobbyist
Disclaimer
Assume You know smth about Docker
This is not a Docker's promo
Outline
1. Container's usage concept
2. Thoughts
3. Case study
4. Experience sharing
"It works in my development environment"
Containers in our Life
Containers in our Life - Evolution
Containers in our Life - Evolution Cont.
Thoughts About Container benefits
Different programming Languages: Java, Ruby, Python, JS/Node.js, Erlang, etc...
Different ecosystems: JVM, JS, Ruby
Application packaging
Different Deployment Models
Run-time environment collision
Container Benefits
Unified form factor:
- Different internals
- Same application run approaches
Docker?
"Docker is a tool for building and deploying applications by packaging them into
lightweight containers."
Pipeline - Traditional
Pipeline - Docker
Terms
Container How you run your application
Images How you store your application
Docker file
FROMdebian:stable
RUNapt-getupdate&&apt-getinstall-y--force-yesapache2
EXPOSE80443
VOLUME["/var/www","/var/log/apache2","/etc/apache2"]
ENTRYPOINT["/usr/sbin/apache2ctl","-D","FOREGROUND"]
Most Popular Docker commands
docker run
docker stop
docker start
docker restart
docker logs
docker exec
docker rm
docker rmi
docker ps
docker images
Docker tips
Use Docker compose
It's impossible to use many container w/o automation tool like Compose
Use Docker for dev and ops
Reuse public images
Avoid manual/custom installation of popular software: db, queue, caches, etc
Docker is convenience app distribution model
Docker Logs
Log Viewer
Aggregated Log Viewer
Docker tips - Image hierarchy
Maven + Docker
alexec/docker-maven-plugin(https://github.com/alexec/docker-maven-plugin)
rhuss/docker-maven-plugin(https://github.com/rhuss/docker-maven-plugin)
spotify/docker-maven-plugin(https://github.com/spotify/docker-maven-plugin)
Gradle + Docker
gesellix/gradle-docker-plugin(https://github.com/gesellix/gradle-docker-plugin)
bmuschko/gradle-docker-plugin(https://github.com/bmuschko/gradle-docker-plugin)
Case Study
Tech stack: Spring MVC, Spring Boot, JS/Angular.js, RoR
3d party : Consul, HAPpoxy, Postgres, Elasticsearch, Redis, Nginx, RabbitMQ
Spring Boot -> Docker
Install Java
Install app JAR file
Configure Image to run Java on start
Add external configuration
Build Image
FROMjava:8
VOLUME/tmp
ADDgs-spring-boot-docker-0.1.0.jarapp.jar
RUNbash-c'touch/app.jar'
ENTRYPOINT["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
Run App
dockerrun-d--namemyservices-p4780:4780--restartalways-v/var/log/my-services:/var/log/SRV
-eCONF_LOCATION=s3://my-storage/test.properties
-eSERVICE_HOST_NAME=`hostname--ip`docker.mycorp.net/myservices:develop
Update staging env
Compare running container with what's been built by CI
Pulls latest images from Docker registry
Stops old version
Launches new version
Register service in Consul
Development Env issues
Developing 2 applications
Requires 9+ apps for properly functional integrated env
Windows Machines :-(
"Golden"/Base VM is hard to maintain
Vagrant ?
"Vagrant is not for managing machines, Vagrant is for managing development
environments. The fact Vagrant spins up machines is mostly historic."
Mitchell Hashimoto
Vagrant features
docker provisioning
docker provider
Vagrant popular commands
vagrant up
vagrant provision
Vagrant docker provisioner works not as expected.
Vagrantfile
VAGRANTFILE_API_VERSION="2"
Vagrant.configure(VAGRANTFILE_API_VERSION)do|config|
config.vm.hostname="docker-host"
#Spinupa"hostbox"forusewiththeDockerprovider
#andthenprovisionitwithDocker
config.vm.box="slowe/ubuntu-trusty-x64"
config.vm.provision"docker"
#Disablesyncedfolders(preventsanNFSerroron"vagrantup")
config.vm.synced_folder".","/vagrant",disabled:true
end
Container setting YAML
---
-name:nginx-01
image:nginx
ports:['80:80','443:443']
-name:redis-01
image:redis
ports:['6379:6379']
Iterate container setting
#IteratethroughtheentriesintheYAMLfile
containers.eachdo|container|
config.vm.definecontainer["name"]do|cntnr|
#DisablesyncedfoldersfortheDockercontainer
#(preventsanNFSerroron"vagrantup")
cntnr.vm.synced_folder".","/vagrant",disabled:true
#ConfiguretheDockerproviderforVagrant
cntnr.vm.provider"docker"do|docker|
#SpecifytheDockerimagetouse,pullvaluefromYAMLfile
docker.image=container["image"]
#Specifyportmappings,pullvaluefromYAMLfile
#Ifomitted,noportsaremapped!
docker.ports=container["ports"]
#SpecifyafriendlynamefortheDockercontainer,pullfromYAMLfile
docker.name=container["name"]
end
end
History Notes
Vagrant
Initial release - March 8, 2010
Current Version - July 17, 2015 - v.1.7.4
Docker
Initial release - March 2013
Current Version - October 12, 2015 - v.1.8.3
References
SO: Should I use Vagrant or Docker.io for creating an isolated environment?
(http://stackoverflow.com/questions/16647069/should-i-use-vagrant-or-docker-io-for-creating-an-isolated-environment)
Running Multiple Docker Containers in Vagrant with YAML(https://github.com/lowescott/learning-
tools/tree/master/vagrant-docker-yaml)
Thank you
22 October 2015
Tags: docker, vagrant(#ZgotmplZ)
Orest Ivasiv
Software engineer, Softserve
Docker hobbyist
http://halyph.com(http://halyph.com)
@halyph(http://twitter.com/halyph)

Vagrant or docker for java dev environment