FORFOR
(JAVA)(JAVA) DEVELOPERSDEVELOPERS
RAFAEL BENEVIDES
@RAFABENE@RAFABENE
1. Docker concepts
2. Creating docker hosts with docker-machine
3. Running docker
4. Creating docker images
5. Running an Application Server in Docker
6. Changing container behaviour
7. 3 ways to deploy an application
8. Composing with docker-compose
9. docker-swarm overview
10. Questions?
AGENDA
Who am I ?
My name is Rafael Benevides
I work for Red Hat since 2009
JBoss Developer Materials lead
Apache DeltaSpike PMC member
Middleware DevOps "guy"
Some facts about me
“ My work consists to help developers
worldwide to be more effective in software
development and promote tools and
practices that help them to be more
productive."e-mail: benevides@redhat.com
Twitter: @rafabene
DISCLAIMER
This presentation should take 45 minutes
It will be 80% live-coding
It won't cover "What is docker?",
"Installing docker", "Motivations to use
docker" topics
But you will see/learn how to use docker
and take you own conclusions about the
motivations to start using it.
Docker Hello world
Docker
Client
Docker
Hub
Docker Host
Daemon
Image 1
Image 2
Image 3
Image 1
Image 2
Image 3
Container 1
Container 2
docker run <image x>
docker run hello-world
docker run <image x>
unix:///var/run/docker.sock
Docker Machine
A L L O W S T H E C R E A T I O N O F D O C K E R H O S T SA L L O W S T H E C R E A T I O N O F D O C K E R H O S T S
DRIVERSDRIVERS
1. AWS - Amazon Web Services
2. Digital Ocean
3. Exoscale
4. Generic ( Fedora, RHEL, CentOS, ... )
5. GCE - Google Compute Enginer
6. IBM Softlayer
7. Microsoft Azure / Hyper-V
8. OpenStack
9. Oracle VirtualBox
10. Rackspace
11. VMware Fusion / vCloud Air / vSphere
USEFUL COMMANDSUSEFUL COMMANDS
docker-machine create -d <driver> <name>
docker-machine ls
docker env <name>
ENV VARSENV VARS
DOCKER_TLS_VERIFY
DOCKER_HOST
DOCKER_CERT_PATH
DOCKER_MACHINE_NAME
Docker commands
DOCKER RUNDOCKER RUN
Creates a new container
docker run <image> command
docker run -it <image> command
docker run --name -it <image> command
docker run --name --rm -it <image> command
docker run -d fedora /bin/bash -c "while true; do echo
hello world; sleep 1; done"
Docker commands
OT HE R DOCK ER COMMANDSOT HE R DOCK ER COMMANDS
docker ps / docker ps -a
docker stop <container> / docker stop -t=1 <container>
docker rm <container> / docker rm `docker ps -aq`
docker logs <container> / docker logs -f <container>
docker attach <container>
docker stats <container>
2 Ways to create Docker Images
COMMIT WAYCOMMIT WAY
docker commit -m "<menssage>" <image name>
docker history <image name>
DOCKERFILE WAYDOCKERFILE WAY
docker build -t <tag> <dockerfile path>
DOCKERFILE REFDOCKERFILE REF
FROM
MAINTAINER
WORKDIR
ENV
RUN
COPY
ADD
EXPOSE
VOLUME
USER
CMD
Dockerfile anatomy
# Use latest jboss/base-jdk:7 image as the base
FROM jboss/base-jdk:8
# Set the WILDFLY_VERSION env variable
ENV WILDFLY_VERSION 9.0.0.Final
# Add the WildFly distribution to /opt, and make wildfly the owner of the extracted tar content
# Make sure the distribution is available from a well-known place
RUN cd $HOME && curl http://download.jboss.org/wildfly/$WILDFLY_VERSION/wildfly-$WILDFLY_VERSION.tar.gz | tar zx &
# Set the JBOSS_HOME env variable
ENV JBOSS_HOME /opt/jboss/wildfly
# Expose the ports we're interested in
EXPOSE 8080
# Set the default command to run on boot
# This will boot WildFly in the standalone mode and bind to all interface
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0"]
WildFly Image example
Changing container behaviour
CHANGING ENV VARCHANGING ENV VAR
docker run -e ...
EXPOSING PORTSEXPOSING PORTS
docker run -P ...
docker run -p <host:container> ...
docker-machine ip
MOUTING VOLUMESMOUTING VOLUMES
docker run -v <host:container> ...
3 Ways to deploy an application
1 - MOUNTING A VOLUME1 - MOUNTING A VOLUME
docker run -v <host:container> ...
2 - ADMINISTRATIVE CONSOLE2 - ADMINISTRATIVE CONSOLE
docker run -p <host:port> ...
3 - INCLUDE INSIDE THE IMAGE3 - INCLUDE INSIDE THE IMAGE
Dockerfile
ADD your-awesome-app.war /opt/jboss/wildfly/standalone/deployments/
Cluster example
Apache HTTPD
+ mod_cluster
Postgres
database
WildFly instances
Linking containers
[ jboss@22ac4068f95f ~]$ cat /etc/hosts
172.17.0.50 22ac4068f95f
127.0.0.1 localhost
172.17.0.43 db 84e9fc3e4455
172.17.0.44 modcluster 13784a898c33
Environment Variables
$DB_NAME
$DB_ENV_LANG
$DB_ENV_PG_VERSION
$DB_ENV_PGDATA
$DB_ENV_POSTGRES_PASSWORD
$DB_ENV_PG_MAJOR
$DB_ENV_POSTGRES_USER
$DB_PORT
$DB_PORT_5432_TCP
$DB_PORT_5432_TCP_PROTO
$DB_PORT_5432_TCP_ADDR
$DB_PORT_5432_TCP_PORT
$MODCLUSTER_NAME
$MODCLUSTER_PORT_80_TCP
$MODCLUSTER_PORT_80_TCP_PORT
$MODCLUSTER_PORT
$MODCLUSTER_PORT_80_TCP_ADDR
$MODCLUSTER_PORT_80_TCP_PROTO
docker run --link <container_name:alias>
Docker compose
docker-compose.yaml
db:
image: postgres
ports:
- "5432:5432"
environment:
- POSTGRES_USER=ticketmonster
- POSTGRES_PASSWORD=ticketmonster-docker
modcluster:
image: goldmann/mod_cluster
ports:
- "80:80"
wildfly:
build: ../Dockerfiles/ticketmonster/
links:
- db:db
- modcluster:modcluster
docker-compose up -d
docker-compose ps
docker-compose logs
docker-compose build
docker-compose scale <service>=x
DISCLAIMER
You're about to see an overview of docker-
swarm
Some issues found:
machine restart
cross-host linking
Docker Swarm
Discovery Services
Docker Hub
Static file
Static list
etcd
consul
zookeeper
Creating a Docker Swarm
echo "Creating cluster ..."
TOKEN=`docker run swarm create`
echo "Got the token " $TOKEN
echo "Creating Swarm master ..."
docker-machine create -d virtualbox --swarm --swarm-master
--swarm-strategy=spread
--swarm-discovery token://$TOKEN swarm-master
echo "Creating Swarm node 01 ..."
docker-machine create -d virtualbox --swarm
--swarm-discovery token://$TOKEN swarm-node-01
echo "Creating Swarm node 02 ..."
docker-machine create -d virtualbox --swarm
--swarm-discovery token://$TOKEN swarm-node-02
eval "$(docker-machine env --swarm swarm-master)"
Strategy
spread*
binpack
random
Kubernetes
Github code
https://github.com
/rafabene
/devops-demo
THANK YOU!THANK YOU!
RAFAEL BENEVIDESRAFAEL BENEVIDES
BENEVIDES@REDHAT.COMBENEVIDES@REDHAT.COM
@RAFABENE@RAFABENE

Docker for (Java) Developers

  • 1.
  • 2.
    1. Docker concepts 2.Creating docker hosts with docker-machine 3. Running docker 4. Creating docker images 5. Running an Application Server in Docker 6. Changing container behaviour 7. 3 ways to deploy an application 8. Composing with docker-compose 9. docker-swarm overview 10. Questions? AGENDA
  • 3.
    Who am I? My name is Rafael Benevides I work for Red Hat since 2009 JBoss Developer Materials lead Apache DeltaSpike PMC member Middleware DevOps "guy" Some facts about me “ My work consists to help developers worldwide to be more effective in software development and promote tools and practices that help them to be more productive."e-mail: [email protected] Twitter: @rafabene
  • 4.
    DISCLAIMER This presentation shouldtake 45 minutes It will be 80% live-coding It won't cover "What is docker?", "Installing docker", "Motivations to use docker" topics But you will see/learn how to use docker and take you own conclusions about the motivations to start using it.
  • 5.
    Docker Hello world Docker Client Docker Hub DockerHost Daemon Image 1 Image 2 Image 3 Image 1 Image 2 Image 3 Container 1 Container 2 docker run <image x> docker run hello-world docker run <image x> unix:///var/run/docker.sock
  • 6.
    Docker Machine A LL O W S T H E C R E A T I O N O F D O C K E R H O S T SA L L O W S T H E C R E A T I O N O F D O C K E R H O S T S DRIVERSDRIVERS 1. AWS - Amazon Web Services 2. Digital Ocean 3. Exoscale 4. Generic ( Fedora, RHEL, CentOS, ... ) 5. GCE - Google Compute Enginer 6. IBM Softlayer 7. Microsoft Azure / Hyper-V 8. OpenStack 9. Oracle VirtualBox 10. Rackspace 11. VMware Fusion / vCloud Air / vSphere USEFUL COMMANDSUSEFUL COMMANDS docker-machine create -d <driver> <name> docker-machine ls docker env <name> ENV VARSENV VARS DOCKER_TLS_VERIFY DOCKER_HOST DOCKER_CERT_PATH DOCKER_MACHINE_NAME
  • 7.
    Docker commands DOCKER RUNDOCKERRUN Creates a new container docker run <image> command docker run -it <image> command docker run --name -it <image> command docker run --name --rm -it <image> command docker run -d fedora /bin/bash -c "while true; do echo hello world; sleep 1; done"
  • 8.
    Docker commands OT HER DOCK ER COMMANDSOT HE R DOCK ER COMMANDS docker ps / docker ps -a docker stop <container> / docker stop -t=1 <container> docker rm <container> / docker rm `docker ps -aq` docker logs <container> / docker logs -f <container> docker attach <container> docker stats <container>
  • 9.
    2 Ways tocreate Docker Images COMMIT WAYCOMMIT WAY docker commit -m "<menssage>" <image name> docker history <image name> DOCKERFILE WAYDOCKERFILE WAY docker build -t <tag> <dockerfile path> DOCKERFILE REFDOCKERFILE REF FROM MAINTAINER WORKDIR ENV RUN COPY ADD EXPOSE VOLUME USER CMD
  • 10.
    Dockerfile anatomy # Uselatest jboss/base-jdk:7 image as the base FROM jboss/base-jdk:8 # Set the WILDFLY_VERSION env variable ENV WILDFLY_VERSION 9.0.0.Final # Add the WildFly distribution to /opt, and make wildfly the owner of the extracted tar content # Make sure the distribution is available from a well-known place RUN cd $HOME && curl http://download.jboss.org/wildfly/$WILDFLY_VERSION/wildfly-$WILDFLY_VERSION.tar.gz | tar zx & # Set the JBOSS_HOME env variable ENV JBOSS_HOME /opt/jboss/wildfly # Expose the ports we're interested in EXPOSE 8080 # Set the default command to run on boot # This will boot WildFly in the standalone mode and bind to all interface CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0"] WildFly Image example
  • 11.
    Changing container behaviour CHANGINGENV VARCHANGING ENV VAR docker run -e ... EXPOSING PORTSEXPOSING PORTS docker run -P ... docker run -p <host:container> ... docker-machine ip MOUTING VOLUMESMOUTING VOLUMES docker run -v <host:container> ...
  • 12.
    3 Ways todeploy an application 1 - MOUNTING A VOLUME1 - MOUNTING A VOLUME docker run -v <host:container> ... 2 - ADMINISTRATIVE CONSOLE2 - ADMINISTRATIVE CONSOLE docker run -p <host:port> ... 3 - INCLUDE INSIDE THE IMAGE3 - INCLUDE INSIDE THE IMAGE Dockerfile ADD your-awesome-app.war /opt/jboss/wildfly/standalone/deployments/
  • 13.
    Cluster example Apache HTTPD +mod_cluster Postgres database WildFly instances
  • 14.
    Linking containers [ jboss@22ac4068f95f~]$ cat /etc/hosts 172.17.0.50 22ac4068f95f 127.0.0.1 localhost 172.17.0.43 db 84e9fc3e4455 172.17.0.44 modcluster 13784a898c33 Environment Variables $DB_NAME $DB_ENV_LANG $DB_ENV_PG_VERSION $DB_ENV_PGDATA $DB_ENV_POSTGRES_PASSWORD $DB_ENV_PG_MAJOR $DB_ENV_POSTGRES_USER $DB_PORT $DB_PORT_5432_TCP $DB_PORT_5432_TCP_PROTO $DB_PORT_5432_TCP_ADDR $DB_PORT_5432_TCP_PORT $MODCLUSTER_NAME $MODCLUSTER_PORT_80_TCP $MODCLUSTER_PORT_80_TCP_PORT $MODCLUSTER_PORT $MODCLUSTER_PORT_80_TCP_ADDR $MODCLUSTER_PORT_80_TCP_PROTO docker run --link <container_name:alias>
  • 15.
    Docker compose docker-compose.yaml db: image: postgres ports: -"5432:5432" environment: - POSTGRES_USER=ticketmonster - POSTGRES_PASSWORD=ticketmonster-docker modcluster: image: goldmann/mod_cluster ports: - "80:80" wildfly: build: ../Dockerfiles/ticketmonster/ links: - db:db - modcluster:modcluster docker-compose up -d docker-compose ps docker-compose logs docker-compose build docker-compose scale <service>=x
  • 16.
    DISCLAIMER You're about tosee an overview of docker- swarm Some issues found: machine restart cross-host linking
  • 17.
    Docker Swarm Discovery Services DockerHub Static file Static list etcd consul zookeeper
  • 18.
    Creating a DockerSwarm echo "Creating cluster ..." TOKEN=`docker run swarm create` echo "Got the token " $TOKEN echo "Creating Swarm master ..." docker-machine create -d virtualbox --swarm --swarm-master --swarm-strategy=spread --swarm-discovery token://$TOKEN swarm-master echo "Creating Swarm node 01 ..." docker-machine create -d virtualbox --swarm --swarm-discovery token://$TOKEN swarm-node-01 echo "Creating Swarm node 02 ..." docker-machine create -d virtualbox --swarm --swarm-discovery token://$TOKEN swarm-node-02 eval "$(docker-machine env --swarm swarm-master)" Strategy spread* binpack random
  • 19.
  • 20.
  • 21.
    THANK YOU!THANK YOU! RAFAELBENEVIDESRAFAEL BENEVIDES [email protected]@REDHAT.COM @RAFABENE@RAFABENE