Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Compose on Swarm

Compose on Swarm

DevOps CodeLabs
Multi-Container Apps
http://eueung.github.io/docker-stuff/multicont

1ec13070abf6996a0bc06b9be103ea85?s=128

Eueung Mulyana

May 21, 2016
Tweet

Transcript

  1. Swarm + Consul + Compose Multi-Container Apps Eueung Mulyana http://eueung.github.io/docker-stuff/multicont

    CodeLabs | Attribution-ShareAlike CC BY-SA 1 / 30
  2. Outline Infrastructure & Cluster Con g - Short Recap Another

    Swarm Arch RPI Voting App 2 / 30
  3. Infrastructure and Cluster Config Short Recap 3 / 30

  4. 4 / 30 Physical Look node1 192.168.1.102 node2 192.168.1.101 node3

    192.168.1.100
  5. 5 / 30 Cluster Discovery via a KV (Consul)

  6. 6 / 30 Swarm Manager Accesses Remote Daemons / Engines

    via Exposed Port
  7. Infrastructure and Cluster Config Another Swarm Arch 7 / 30

  8. 8 / 30 Using Legacy (now Optional) Swarm Join

  9. 9 / 30 It's now acctually like this

  10. $ s o u r c e ~ / .

    d v m / d v m . s h $ d v m u s e 1 . 1 0 . 2 N o w u s i n g D o c k e r 1 . 1 0 . 2 $ . / s t a r t - c o n s u l . s h n o d e 1 . l o c a l 1 9 2 . 1 6 8 . 1 . 1 0 2 8 b 5 4 a b 3 1 0 4 b 1 8 f 7 5 8 1 4 e 5 c 0 3 f 8 9 f 3 7 7 8 a c a a d 2 6 3 f 7 3 1 6 9 5 1 6 3 c f 5 2 c 9 5 b 1 a 4 f 4 f # . / s t a r t - c o n s u l . s h # - - - # ! / b i n / b a s h f u n c t i o n g e t i p ( ) { ( t r a c e r o u t e $ 1 2 > & 1 | h e a d - n 1 | c u t - d \ ( - f 2 | c u t I P _ A D D R E S S = $ ( g e t i p $ 1 ) e c h o $ I P _ A D D R E S S d o c k e r - H $ I P _ A D D R E S S : 2 3 7 5 r u n \ - d - - n e t = h o s t - - n a m e = c o n s u l \ - v / d a t a - p 8 5 0 0 : 8 5 0 0 \ h y p r i o t / r p i - c o n s u l : 0 . 6 . 4 a g e n t - s e r v e r - d a t a - d i r / d a t a - b o o t s t r a p - e x p e c t - u i - d i r = / u i \ - a d v e r t i s e = $ I P _ A D D R E S S - b i n d = $ I P _ A D D R E S S - c l i e n t = $ I P _ A D D R E S S 10 / 30 Start Consul @ node1
  11. Consul UI 11 / 30

  12. $ . / s t a r t - s

    w a r m . s h R u n n i n g S w a r m A g e n t a t 1 9 2 . 1 6 8 . 1 . 1 0 0 b 8 7 9 a 0 4 3 2 3 c 8 1 7 4 3 2 e 9 5 a 9 7 0 b b f 7 1 a 6 e 0 3 f d 6 a e 8 9 5 f a 6 4 3 a 7 f e 7 5 f d 1 2 c 7 8 d 0 6 d R u n n i n g S w a r m A g e n t a t 1 9 2 . 1 6 8 . 1 . 1 0 1 f 4 7 f 6 c 6 b 2 5 8 f 8 f 0 3 e 1 a d 4 4 1 0 4 9 e 2 c 4 3 2 0 b 0 a 1 3 8 e 6 d 8 e a c 5 2 b d a a 5 f 7 0 c a 8 0 e 7 2 d R u n n i n g S w a r m A g e n t a t 1 9 2 . 1 6 8 . 1 . 1 0 2 4 7 3 4 6 d 3 0 d 3 5 d 8 1 7 4 b 4 1 9 9 5 f a 3 4 e f a a 6 9 c c 6 d 2 d e 6 c 2 0 9 1 e 2 9 7 5 0 d 7 e 2 6 4 c 6 d 4 8 1 6 d e 5 e e 5 7 f 8 e 2 0 e f 3 e f 1 5 c d 6 8 f 8 7 3 6 2 0 3 1 9 2 0 2 4 8 6 5 1 0 e 8 8 c 1 d 2 2 b f d b d 8 e 4 e c 9 3 5 a # . / s t a r t - s w a r m . s h # - - - # ! / b i n / b a s h a r r = ( " 1 9 2 . 1 6 8 . 1 . 1 0 0 " " 1 9 2 . 1 6 8 . 1 . 1 0 1 " " 1 9 2 . 1 6 8 . 1 . 1 0 2 " ) I P _ C O N S U L = " 1 9 2 . 1 6 8 . 1 . 1 0 2 " I P _ S W A R M M A S T E R = $ I P _ C O N S U L f o r I P i n " $ { a r r [ @ ] } " ; d o e c h o " R u n n i n g S w a r m A g e n t a t $ I P " d o c k e r - H $ I P : 2 3 7 5 r u n \ - d - - n a m e = s w a r m - a g e n t \ h y p r i o t / r p i - s w a r m : 1 . 2 . 1 \ j o i n - a d v e r t i s e $ I P : 2 3 7 5 \ c o n s u l : / / $ I P _ C O N S U L : 8 5 0 0 d o n e d o c k e r - H $ I P _ S W A R M M A S T E R : 2 3 7 5 r u n \ - d - p 1 0 0 0 0 : 6 0 0 0 - - n a m e = s w a r m - m a s t e r \ h y p r i o t / r p i - s w a r m : 1 . 2 . 1 m a n a g e - H 0 . 0 . 0 . 0 : 6 0 0 0 \ c o n s u l : / / $ I P _ C O N S U L : 8 5 0 0 12 / 30 Start Swarm agent @ all nodes manager @ node1
  13. Consul UI 13 / 30

  14. Consul UI 14 / 30

  15. $ e x p o r t D O C

    K E R _ H O S T = t c p : / / 1 9 2 . 1 6 8 . 1 . 1 0 2 : 1 0 0 0 0 $ d o c k e r i n f o . . . $ d o c k e r p s C O N T A I N E R I D I M A G E C O M M A N D C R E A T E D d e 5 e e 5 7 f 8 e 2 0 h y p r i o t / r p i - s w a r m : 1 . 2 . 1 " / s w a r m m a n a g e - H 0 . 0 " 3 m i n u t e s a g o 4 7 3 4 6 d 3 0 d 3 5 d h y p r i o t / r p i - s w a r m : 1 . 2 . 1 " / s w a r m j o i n - a d v e r t i " 3 m i n u t e s a g o f 4 7 f 6 c 6 b 2 5 8 f h y p r i o t / r p i - s w a r m : 1 . 2 . 1 " / s w a r m j o i n - a d v e r t i " 3 m i n u t e s a g o b 8 7 9 a 0 4 3 2 3 c 8 h y p r i o t / r p i - s w a r m : 1 . 2 . 1 " / s w a r m j o i n - a d v e r t i " 3 m i n u t e s a g o 8 b 5 4 a b 3 1 0 4 b 1 h y p r i o t / r p i - c o n s u l : 0 . 6 . 4 " / c o n s u l a g e n t - s e r v e " 5 m i n u t e s a g o 15 / 30 Check
  16. RPI Voting App Credit: @jmMeessen , @dduportal 16 / 30

  17. 5 Containers, 2 Networks 17 / 30

  18. # . / t a g - i m a

    g e s . s h # ! / b i n / b a s h d o c k e r t a g t h e c a p t a i n s s h a c k / r p i - w o r k e r t h e c a p t a i n s s h a c k / r p i - w o r k e r : v 1 d o c k e r t a g t h e c a p t a i n s s h a c k / r p i - v o t i n g - a p p t h e c a p t a i n s s h a c k / r p i - v o t i n g - a p p : v 1 d o c k e r t a g t h e c a p t a i n s s h a c k / r p i - r e s u l t - a p p t h e c a p t a i n s s h a c k / r p i - r e s u l t - a p p : v 1 d o c k e r t a g t h e c a p t a i n s s h a c k / p o s t g r e s - a r m t h e c a p t a i n s s h a c k / p o s t g r e s - a r m : v 1 . / s a v e - i m a g e s . s h # ! / b i n / b a s h d o c k e r s a v e - o r p i - w o r k e r . t a r t h e c a p t a i n s s h a c k / r p i - w o r k e r d o c k e r s a v e - o r p i - v o t i n g - a p p . t a r t h e c a p t a i n s s h a c k / r p i - v o t i n g - a p p d o c k e r s a v e - o r p i - r e s u l t - a p p . t a r t h e c a p t a i n s s h a c k / r p i - r e s u l t - a p p d o c k e r s a v e - o p o s t g r e s - a r m . t a r t h e c a p t a i n s s h a c k / p o s t g r e s - a r m # . / l o a d - i m a g e s . s h # ! / b i n / b a s h d o c k e r l o a d - i r p i - w o r k e r . t a r d o c k e r l o a d - i r p i - v o t i n g - a p p . t a r d o c k e r l o a d - i r p i - r e s u l t - a p p . t a r d o c k e r l o a d - i p o s t g r e s - a r m . t a r s f t p > m k d i r v o t i n g s f t p > p u t - r v o t i n g $ r m - f v o t i n g / * & & r m d i r v o t i n g 18 / 30 Optional Preparation tag, save, load
  19. d b : i m a g e : t

    h e c a p t a i n s s h a c k / p o s t g r e s - a r m : v 1 v o l u m e s : - d b - d a t a : / v a r / l i b / p o s t g r e s q l / d a t a n e t w o r k s : - b a c k - t i e r r e s u l t - a p p : i m a g e : t h e c a p t a i n s s h a c k / r p i - r e s u l t - a p p : v 1 p o r t s : - " 5 0 0 1 : 8 0 " l i n k s : - d b n e t w o r k s : - f r o n t - t i e r - b a c k - t i e r v o l u m e s : d b - d a t a : { } n e t w o r k s : f r o n t - t i e r : d r i v e r : o v e r l a y b a c k - t i e r : d r i v e r : o v e r l a y 19 / 30 docker-compose.yml v e r s i o n : ' 2 ' s e r v i c e s : v o t i n g - a p p : i m a g e : t h e c a p t a i n s s h a c k / r p i - v o t i n g - a p p : v 1 p o r t s : - " 5 0 0 0 : 8 0 " l i n k s : - r e d i s n e t w o r k s : - f r o n t - t i e r - b a c k - t i e r r e d i s : i m a g e : h y p r i o t / r p i - r e d i s : 3 . 0 . 4 e x p o s e : [ " 6 3 7 9 " ] n e t w o r k s : - b a c k - t i e r w o r k e r : i m a g e : t h e c a p t a i n s s h a c k / r p i - w o r k e r : v 1 d e p e n d s _ o n : - d b - r e d i s n e t w o r k s : - b a c k - t i e r
  20. $ d o c k e r - c o

    m p o s e u p - d C r e a t i n g n e t w o r k " v o t e a p p s _ f r o n t - t i e r " w i t h d r i v e r " o v e r l a y " C r e a t i n g n e t w o r k " v o t e a p p s _ b a c k - t i e r " w i t h d r i v e r " o v e r l a y " C r e a t i n g v o l u m e " v o t e a p p s _ d b - d a t a " w i t h d e f a u l t d r i v e r C r e a t i n g v o t e a p p s _ r e d i s _ 1 C r e a t i n g v o t e a p p s _ d b _ 1 C r e a t i n g v o t e a p p s _ v o t i n g - a p p _ 1 C r e a t i n g v o t e a p p s _ w o r k e r _ 1 C r e a t i n g v o t e a p p s _ r e s u l t - a p p _ 1 $ d o c k e r p s C O N T A I N E R I D I M A G E C O M M A N D C R E A T E 1 3 3 9 0 a e 0 7 6 3 4 t h e c a p t a i n s s h a c k / r p i - r e s u l t - a p p : v 1 " n o d e s e r v e r . j s " 1 4 s e c f b 7 7 8 8 e 2 1 d c f t h e c a p t a i n s s h a c k / r p i - w o r k e r : v 1 " j a v a - j a r / w o r k e r - j a " 1 4 s e c 0 2 d a 4 f d 6 d 3 9 5 t h e c a p t a i n s s h a c k / p o s t g r e s - a r m : v 1 " / d o c k e r - e n t r y p o i n t . s " 1 9 s e c 9 2 7 1 1 6 1 c f f d 0 h y p r i o t / r p i - s w a r m : 1 . 2 . 1 " / s w a r m m a n a g e - H 0 . 0 " 2 m i n u 5 0 9 4 d 3 5 6 a 1 4 1 h y p r i o t / r p i - s w a r m : 1 . 2 . 1 " / s w a r m j o i n - a d v e r t i " 2 m i n u 4 3 c 6 c 9 9 1 4 1 6 7 h y p r i o t / r p i - s w a r m : 1 . 2 . 1 " / s w a r m j o i n - a d v e r t i " 2 m i n u 3 8 d c 4 6 7 9 4 c 3 0 h y p r i o t / r p i - c o n s u l : 0 . 6 . 4 " / c o n s u l a g e n t - s e r v e " 2 m i n u 4 9 5 2 e 2 4 c e 4 5 2 t h e c a p t a i n s s h a c k / r p i - v o t i n g - a p p : v 1 " p y t h o n a p p . p y " 1 0 h o u a c 9 9 8 b 6 5 7 9 2 c h y p r i o t / r p i - r e d i s : 3 . 0 . 4 " / e n t r y p o i n t . s h r e d i s " 1 0 h o u 9 4 e 8 3 a a 0 3 8 b 1 h y p r i o t / r p i - s w a r m : 1 . 2 . 1 " / s w a r m j o i n - a d v e r t i " 1 0 h o u # r e s t a r t i f n e c e s s a r y $ d o c k e r - c o m p o s e s t o p & & d o c k e r - c o m p o s e r m - f 20 / 30 Ready for Show
  21. $ d o c k e r - c o

    m p o s e p s N a m e C o m m a n d S t a t e P o r t s - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - v o t e a p p s _ d b _ 1 / d o c k e r - e n t r y p o i n t . s h p o s t g r e s U p 5 4 3 2 / t c p v o t e a p p s _ r e d i s _ 1 / e n t r y p o i n t . s h r e d i s - s e r v e r U p 6 3 7 9 / t c p v o t e a p p s _ r e s u l t - a p p _ 1 n o d e s e r v e r . j s U p 1 9 2 . 1 6 8 . 1 . 1 0 0 : 5 0 0 1 - > v o t e a p p s _ v o t i n g - a p p _ 1 p y t h o n a p p . p y U p 1 9 2 . 1 6 8 . 1 . 1 0 1 : 5 0 0 0 - > v o t e a p p s _ w o r k e r _ 1 j a v a - j a r / w o r k e r - j a r - w i t h . . . U p r o o t @ n o d e 3 i n ~ $ d o c k e r n e t w o r k l s N E T W O R K I D N A M E D R I V E R 8 a d d 7 9 a f 5 b f 7 v o t e a p p s _ f r o n t - t i e r o v e r l a y c 9 c 8 5 0 3 d a 2 d 8 v o t e a p p s _ b a c k - t i e r o v e r l a y f 0 d c e 7 2 4 0 3 4 9 d o c k e r _ g w b r i d g e b r i d g e 8 c b e 7 e 0 8 5 f a d n o n e n u l l e c 2 7 2 b 5 9 c f d 7 h o s t h o s t 4 5 9 2 6 9 6 e b f 1 9 b r i d g e b r i d g e 21 / 30 Ready for Show
  22. voting-app 22 / 30

  23. $ d o c k e r l o g

    s - f 2 d e 6 C o n n e c t e d t o r e d i s W a t c h i n g v o t e q u e u e P r o c e s s i n g v o t e f o r ' a ' b y ' 8 4 a 5 1 f 3 1 5 b 6 9 e 0 4 a ' 23 / 30 redis log
  24. result-app 24 / 30

  25. voting-app 25 / 30

  26. $ d o c k e r l o g

    s - f 2 d e 6 C o n n e c t e d t o r e d i s W a t c h i n g v o t e q u e u e P r o c e s s i n g v o t e f o r ' a ' b y ' 8 4 a 5 1 f 3 1 5 b 6 9 e 0 4 a ' P r o c e s s i n g v o t e f o r ' a ' b y ' 8 4 a 5 1 f 3 1 5 b 6 9 e 0 4 a ' P r o c e s s i n g v o t e f o r ' b ' b y ' 8 f 3 e e 3 5 0 c 2 a e c 3 f 5 ' 26 / 30 redis log
  27. result-app 27 / 30

  28. Refs 28 / 30

  29. Refs 1. jmMeessen/rpi-voting-app: A dockerized voting application demo, adapted for

    Raspberry PI 2. @dduportal - Swarm on Raspberry Pis 3. docker/example-voting-app: Example Docker Compose app 29 / 30
  30. END Eueung Mulyana http://eueung.github.io/docker-stuff/multicont CodeLabs | Attribution-ShareAlike CC BY-SA 30

    / 30