Upload
orest-ivasiv
View
560
Download
4
Embed Size (px)
Citation preview
Vagrant or Docker for Java devenvironment?Engineering Communities
22 October 2015
Orest IvasivSoftware engineer, SoftserveDocker 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 intolightweight containers."
Pipeline - Traditional
Pipeline - Docker
Terms
Container How you run your application
Images How you store your application
Docker file
FROM debian:stableRUN apt-get update && apt-get install -y --force-yes apache2EXPOSE 80 443VOLUME ["/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
FROM java:8VOLUME /tmpADD gs-spring-boot-docker-0.1.0.jar app.jarRUN bash -c 'touch /app.jar'ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
Run App
docker run -d --name myservices -p 4780:4780 --restart always -v /var/log/my-services:/var/log/SRV \ -e CONF_LOCATION=s3://my-storage/test.properties \-e SERVICE_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 developmentenvironments. 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"
# Spin up a "host box" for use with the Docker provider # and then provision it with Docker config.vm.box = "slowe/ubuntu-trusty-x64" config.vm.provision "docker"
# Disable synced folders (prevents an NFS error on "vagrant up") config.vm.synced_folder ".", "/vagrant", disabled: trueend
Container setting YAML
---- name: nginx-01 image: nginx ports: ['80:80', '443:443']- name: redis-01 image: redis ports: ['6379:6379']
Iterate container setting
# Iterate through the entries in the YAML filecontainers.each do |container|config.vm.define container["name"] do |cntnr|
# Disable synced folders for the Docker container # (prevents an NFS error on "vagrant up") cntnr.vm.synced_folder ".", "/vagrant", disabled: true
# Configure the Docker provider for Vagrant cntnr.vm.provider "docker" do |docker|
# Specify the Docker image to use, pull value from YAML file docker.image = container["image"]
# Specify port mappings, pull value from YAML file # If omitted, no ports are mapped! docker.ports = container["ports"]
# Specify a friendly name for the Docker container, pull from YAML file docker.name = container["name"] endend
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 2015Tags: docker, vagrant (#ZgotmplZ)
Orest IvasivSoftware engineer, SoftserveDocker hobbyisthttp://halyph.com (http://halyph.com)
@halyph (http://twitter.com/halyph)