21
FOR FOR (JAVA) (JAVA) DEVELOPERS DEVELOPERS RAFAEL BENEVIDES @RAFABENE @RAFABENE

Docker for (Java) Developers

Embed Size (px)

Citation preview

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 developersworldwide to be more ef fective in softwaredevelopment and promote tools andpractices that help them to be moreproductive."e-mail : [email protected]

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 usedocker" topics

But you will see/learn how to use dockerand take you own conclusions about themotivations to start using it.

Docker Hello world

DockerClient

DockerHub

Docker Host

Daemon

Image 1

Image 2

Image 3

Image 1

Image 2

Image 3

Conta iner 1

Conta iner 2docker run <image x>

docker run hello-world

docker run <image x>

u n i x : / / / va r /ru n /d o c ke r . so c k

Docker MachineA 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 Soft layer

7. Microsof t Azure / Hyper-V

8. OpenStack

9. Oracle Vir tualBox

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

D O C K E R R U ND O C K E R R U NCreates 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 echohello world; sleep 1 ; done"

Docker commands

OT H E R D O C K E R C O M M A N D SOT H E R D O C K E R C O M M A N D S

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 la test jboss/base- jdk :7 image as the baseFROM jboss/base- jdk :8

# Set the WILDFLY_VERSION env var iab leENV WILDFLY_VERSION 9 .0 .0 .F ina l

# Add the Wi ldF ly d i st r ibut ion to /opt , and make w i ldfly the owner o f the ext racted tar content# Make sure the d ist r ibut ion i s ava i lab le f rom a we l l -known p laceRUN cd $HOME && cur l h t tp ://download . jboss .org/wi ldfly/$WILDFLY_VERSION/wi ldfly-$WILDFLY_VERSION. tar .gz | ta r zx && mv

# Set the JBOSS_HOME env var iab leENV JBOSS_HOME /opt/ jboss/wi ldfly

# Expose the por ts we ' re in terested inEXPOSE 8080

# Set the defau l t command to run on boot# Th is w i l l boot Wi ldF ly in the standa lone mode and b ind to a l l in ter faceCMD [ "/opt/ jboss/wi ldfly/b in/standa lone .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

Postgresdatabase

WildFly instances

Linking containers

[ jboss@22ac4068f95f ~]$ cat /etc/hosts

172 . 17 .0 .50 22ac4068f95f127 .0 .0 . 1 l oca lhost172 . 17 .0 .43 db 84e9fc3e4455172 . 17 .0 .44 modc luster 13784a898c33

Env i ronment Var iab les

$DB_NAME $DB_ENV_L ANG $DB_ENV_PG_VERSION $DB_ENV_PGDATA $DB_ENV_POSTGRES_PASSWORD $DB_ENV_PG_MA JOR $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 --l ink <container_name:al ias>

Docker compose

docker-compose .yaml

db : image : postgres por ts : - "5432 :5432" env i ronment : - POSTGRES_USER=t icketmonster - POSTGRES_PASSWORD=t icketmonster-dockermodc luster : image : go ldmann/mod_c luster por ts : - "80 :80"wi ldfly : bu i ld : . . /Dockerfil es/t i cketmonster/ l inks : - db :db - modc luster :modc luster

docker-compose up -d

docker-compose ps

docker-compose logs

docker-compose build

docker-compose scale <service>=x

DISCLAIMERYou're about to see an overview of docker-swarm

Some issues found:

machine restartcross-host linking

Docker Swarm

Discovery Services

Docker HubStatic fileStatic l istetcdconsulzookeeper

Creating a Docker Swarmecho "Creating cluster ..."TOKEN=`docker run swarm create`echo "Got the token " $TOKENecho "Creating Swarm master ..."docker-machine create -d virtualbox --swarm --swarm-master --swarm-strategy=spread --swarm-discovery token://$TOKEN swarm-masterecho "Creating Swarm node 01 ..."docker-machine create -d virtualbox --swarm --swarm-discovery token://$TOKEN swarm-node-01echo "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*binpackrandom

Kubernetes

Github code

https://github.com

/rafabene

/devops-demo

THANK YOU!THANK YOU!

RAFAEL BENEVIDESRAFAEL BENEVIDES

[email protected]@REDHAT.COM

@ R A FA B E N E@ R A FA B E N E