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

Docker Swarm + Machine

Docker Swarm + Machine

DevOps CodeLabs
Docker Swarm + Machine
Docker - Container Clustering
http://eueung.github.io/docker-stuff/swarm

Eueung Mulyana

May 06, 2016
Tweet

More Decks by Eueung Mulyana

Other Decks in Technology

Transcript

  1. Docker Swarm + Machine Docker - Container Clustering Eueung Mulyana

    http://eueung.github.io/docker-stuff/swarm CodeLabs | Attribution-ShareAlike CC BY-SA 1 / 31
  2. Docker Engine When people say "Docker" they typically mean Docker

    Engine, the client-server application made up of the Docker daemon, a REST API that speci es interfaces for interacting with the daemon, and a command line interface (CLI) client that talks to the daemon (through the REST API wrapper). Docker Engine accepts docker commands from the CLI, such as d o c k e r r u n < i m a g e > , d o c k e r p s to list running containers, d o c k e r i m a g e s to list images, and so on. Engine is the core of Docker and nothing else will run without it. Ref: docker.com 4 / 31
  3. Docker daemon The Docker daemon runs on a host machine.

    The user does not directly interact with the daemon, but instead through the Docker client. Docker client The Docker client, in the form of the docker binary, is the primary user interface to Docker. It accepts commands from the user and communicates back and forth with a Docker daemon. Ref: docker.com 6 / 31 Docker Architecture Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers. Both the Docker client and the daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon. The Docker client and daemon communicate via sockets or through a RESTful API.
  4. Docker Machine is a tool for provisioning and managing your

    Dockerized hosts (hosts with Docker Engine on them). Typically, you install Docker Machine on your local system. Docker Machine has its own command line client d o c k e r - m a c h i n e and the Docker Engine client, d o c k e r . You can use Machine to install Docker Engine on one or more virtual systems. These virtual systems can be local (as when you use Machine to install and run Docker Engine in VirtualBox on Mac or Windows) or remote (as when you use Machine to provision Dockerized hosts on cloud providers). The Dockerized hosts themselves can be thought of, and are sometimes referred to as, managed "machines". Using d o c k e r - m a c h i n e commands, you can start, inspect, stop, and restart a managed host, upgrade the Docker client and daemon, and con gure a Docker client to talk to your host. Point the Machine CLI at a running, managed host, and you can run docker commands directly on that host. For example, run d o c k e r - m a c h i n e e n v d e f a u l t to point to a host called d e f a u l t , follow on-screen instructions to complete env setup, and run d o c k e r p s , d o c k e r r u n h e l l o - w o r l d , and so forth. 9 / 31 Docker Machine vs. Docker Engine Ref: Machine Overview
  5. Docker Machine 10 / 31 Install and run Docker on

    Mac or Windows Provision and manage multiple remote Docker hosts Provision Swarm clusters
  6. $ c u r l - L h t t

    p s : / / g i t h u b . c o m / d o c k e r / m a c h i n e / r e l e a s e s / d o w n l o a d / v 0 . 6 . 0 / d o c k e r - m a c h i n e - ` u n a m e $ c h m o d + x / u s r / l o c a l / b i n / d o c k e r - m a c h i n e $ d o c k e r - m a c h i n e v e r s i o n d o c k e r - m a c h i n e v e r s i o n 0 . 7 . 0 , b u i l d a 6 5 0 a 4 0 $ d o c k e r - m a c h i n e l s N A M E A C T I V E D R I V E R S T A T E U R L S W A R M D O C K E R E R R O R S Install 12 / 31
  7. Create a Machine $ d o c k e r

    - m a c h i n e c r e a t e - - d r i v e r v i r t u a l b o x d e f a u l t C r e a t i n g C A : / h o m e / e m / . d o c k e r / m a c h i n e / c e r t s / c a . p e m C r e a t i n g c l i e n t c e r t i f i c a t e : / h o m e / e m / . d o c k e r / m a c h i n e / c e r t s / c e r t . p e m R u n n i n g p r e - c r e a t e c h e c k s . . . ( d e f a u l t ) I m a g e c a c h e d i r e c t o r y d o e s n o t e x i s t , c r e a t i n g i t a t / h o m e / e m / . d o c k e r / m a c h i n e / ( d e f a u l t ) N o d e f a u l t B o o t 2 D o c k e r I S O f o u n d l o c a l l y , d o w n l o a d i n g t h e l a t e s t r e l e a s e . . . ( d e f a u l t ) L a t e s t r e l e a s e f o r g i t h u b . c o m / b o o t 2 d o c k e r / b o o t 2 d o c k e r i s v 1 . 1 1 . 1 ( d e f a u l t ) D o w n l o a d i n g / h o m e / e m / . d o c k e r / m a c h i n e / c a c h e / b o o t 2 d o c k e r . i s o f r o m h t t p s : / / g i t h u b ( d e f a u l t ) 0 % . . . . 1 0 % . . . . 2 0 % . . . . 3 0 % . . . . 4 0 % . . . . 5 0 % . . . . 6 0 % . . . . 7 0 % . . . . 8 0 % . . . . 9 0 % . . . . 1 0 0 % C r e a t i n g m a c h i n e . . . ( d e f a u l t ) C o p y i n g / h o m e / e m / . d o c k e r / m a c h i n e / c a c h e / b o o t 2 d o c k e r . i s o t o / h o m e / e m / . d o c k e r / m a c ( d e f a u l t ) C r e a t i n g V i r t u a l B o x V M . . . ( d e f a u l t ) C r e a t i n g S S H k e y . . . ( d e f a u l t ) S t a r t i n g t h e ( d e f a u l t ) C h e c k n e t w o r k t o r e - c r e a t e i f n e e d e d . . . ( d e f a u l t ) F o u n d a n e w h o s t - o n l y a d a p t e r : " v b o x n e t 1 " ( d e f a u l t ) W a i t i n g f o r a n I P . . . W a i t i n g f o r m a c h i n e t o b e r u n n i n g , t h i s m a y t a k e a f e w m i n u t e s . . . D e t e c t i n g o p e r a t i n g s y s t e m o f c r e a t e d i n s t a n c e . . . W a i t i n g f o r S S H t o b e a v a i l a b l e . . . D e t e c t i n g t h e p r o v i s i o n e r . . . P r o v i s i o n i n g w i t h b o o t 2 d o c k e r . . . C o p y i n g c e r t s t o t h e l o c a l m a c h i n e d i r e c t o r y . . . C o p y i n g c e r t s t o t h e r e m o t e m a c h i n e . . . S e t t i n g D o c k e r c o n f i g u r a t i o n o n t h e r e m o t e d a e m o n . . . C h e c k i n g c o n n e c t i o n t o D o c k e r . . . D o c k e r i s u p a n d r u n n i n g ! T o s e e h o w t o c o n n e c t y o u r D o c k e r C l i e n t t o t h e D o c k e r E n g i n e r u n n i n g o n t h i s v i r t u a l m a $ d o c k e r - m a c h i n e l s N A M E A C T I V E D R I V E R S T A T E U R L S W A R M D O C K E R d e f a u l t - v i r t u a l b o x R u n n i n g t c p : / / 1 9 2 . 1 6 8 . 9 9 . 1 0 0 : 2 3 7 6 v 1 . 1 1 . 1 13 / 31
  8. Connect $ d o c k e r - m

    a c h i n e e n v d e f a u l t e x p o r t D O C K E R _ T L S _ V E R I F Y = " 1 " 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 . 9 9 . 1 0 0 : 2 3 7 6 " e x p o r t D O C K E R _ C E R T _ P A T H = " / h o m e / e m / . d o c k e r / m a c h i n e / m a c h i n e s / d e f a u l t " e x p o r t D O C K E R _ M A C H I N E _ N A M E = " d e f a u l t " # R u n t h i s c o m m a n d t o c o n f i g u r e y o u r s h e l l : # e v a l $ ( d o c k e r - m a c h i n e e n v d e f a u l t ) $ e v a l $ ( d o c k e r - m a c h i n e e n v d e f a u l t ) $ d o c k e r i m a g e s R E P O S I T O R Y T A G I M A G E I D C R E A T E D S I Z E $ e n v | g r e p D O C K E R D O C K E R _ H O S T = t c p : / / 1 9 2 . 1 6 8 . 9 9 . 1 0 0 : 2 3 7 6 D O C K E R _ M A C H I N E _ N A M E = d e f a u l t D O C K E R _ T L S _ V E R I F Y = 1 D O C K E R _ C E R T _ P A T H = / h o m e / e m / . d o c k e r / m a c h i n e / m a c h i n e s / d e f a u l t $ d o c k e r - m a c h i n e l s N A M E A C T I V E D R I V E R S T A T E U R L S W A R M D O C K E R d e f a u l t * v i r t u a l b o x R u n n i n g t c p : / / 1 9 2 . 1 6 8 . 9 9 . 1 0 0 : 2 3 7 6 v 1 . 1 1 . 1 14 / 31
  9. Work $ d o c k e r r u

    n b u s y b o x e c h o h e l l o w o r l d U n a b l e t o f i n d i m a g e ' b u s y b o x : l a t e s t ' l o c a l l y l a t e s t : P u l l i n g f r o m l i b r a r y / b u s y b o x . . . 3 8 5 e 2 8 1 3 0 0 c c : P u l l c o m p l e t e . . . a 3 e d 9 5 c a e b 0 2 : P D i g e s t : s h a 2 5 6 : 4 a 8 8 7 a 2 3 2 6 e c 9 e 0 f a 9 0 c c e 7 b 4 7 6 4 b 0 e 6 2 7 b 5 d 6 a f c b 8 1 a 3 f 7 3 c 8 5 d c 2 9 c e a 0 0 0 4 8 S t a t u s : D o w n l o a d e d n e w e r i m a g e f o r b u s y b o x : l a t e s t h e l l o w o r l d $ d o c k e r i m a g e s R E P O S I T O R Y T A G I M A G E I D C R E A T E D S I Z E b u s y b o x l a t e s t 4 7 b c c 5 3 f 7 4 d c 6 w e e k s a g o 1 . 1 1 3 $ d o c k e r - m a c h i n e i p d e f a u l t 1 9 2 . 1 6 8 . 9 9 . 1 0 0 $ d o c k e r p s - a 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 S T A T U S 0 f b 8 a f c a 0 5 e a b u s y b o x " e c h o h e l l o w o r l d " 2 m i n u t e s a g o E x i t e d $ d o c k e r r u n - d - p 8 0 0 0 : 8 0 n g i n x U n a b l e t o f i n d i m a g e ' n g i n x : l a t e s t ' l o c a l l y l a t e s t : P u l l i n g f r o m l i b r a r y / n g i n x e f d 2 6 e c c 9 5 4 8 : P u l l c o m p l e t e . . . 8 d d c 2 d 7 b e b 9 1 : P u l l c o m p l e t e D i g e s t : s h a 2 5 6 : 2 c a 2 6 3 8 e 5 5 3 1 9 b 7 b c 0 c 7 d 0 2 8 2 0 9 e a 6 9 b 1 3 6 8 e 9 5 b 0 1 3 8 3 e 6 6 d f e 7 e 4 f 4 3 7 8 0 9 2 6 d S t a t u s : D o w n l o a d e d n e w e r i m a g e f o r n g i n x : l a t e s t a 8 e b 8 f 2 5 7 c c 1 a 7 4 7 f f 5 b d 3 0 c 0 5 6 f c f 5 f e 1 7 3 d e 8 f b 0 7 8 1 2 6 5 e e d 5 9 5 a b 7 c d 6 9 b 4 0 $ 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 S T A a 8 e b 8 f 2 5 7 c c 1 n g i n x " n g i n x - g ' d a e m o n o f f " 1 0 s e c o n d s a g o U p 15 / 31
  10. Work # o r $ c u r l $

    ( d o c k e r - m a c h i n e i p d e f a u l t ) : 8 0 0 0 $ d o c k e r - m a c h i n e s t o p S t o p p i n g " d e f a u l t " . . . M a c h i n e " d e f a u l t " w a s s t o p p e d . # w i t h o u t e x p l i c i t n a m e - > d e f a u l t $ e n v | g r e p D O C K E R D O C K E R _ H O S T = t c p : / / 1 9 2 . 1 6 8 . 9 9 . 1 0 0 : 2 3 7 6 D O C K E R _ M A C H I N E _ N A M E = d e f a u l t D O C K E R _ T L S _ V E R I F Y = 1 D O C K E R _ C E R T _ P A T H = / h o m e / e m / . d o c k e r / m a c h i n e / m a c h i n e s / d e f a u l t $ d o c k e r i m a g e s A n e r r o r o c c u r r e d t r y i n g t o c o n n e c t : G e t h t t p s : / / 1 9 2 . 1 6 8 . 9 9 . 1 0 0 : 2 3 7 6 / v 1 . 2 3 / i m a g e s / j s o n : $ e v a l $ ( d o c k e r - m a c h i n e e n v - u ) $ e n v | g r e p D O C K E R $ d o c k e r i m a g e s R E P O S I T O R Y T A G I M A G E I D C R E A T E D c o m p o s e t e s t _ w e b l a t e s t e 7 d 6 2 b a 3 0 c 2 0 4 d a y s a g o w e b l a t e s t d 6 f 2 5 a 9 b f 6 3 2 4 d a y s a g o r e d i s l a t e s t 9 a 4 5 0 a e 4 1 8 d 8 4 d a y s a g o 17 / 31
  11. Docker Swarm is native clustering for Docker. It turns a

    pool of Docker hosts into a single, virtual Docker host. Because Docker Swarm serves the standard Docker API, any tool that already communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts. 19 / 31 Docker Swarm Ref: Mike Goelzer, Swarm: Docker Native Clustering, Swarm Overview
  12. $ d o c k e r - m a

    c h i n e c r e a t e - d v i r t u a l b o x m a n a g e r $ d o c k e r - m a c h i n e c r e a t e - d v i r t u a l b o x a g e n t 1 $ d o c k e r - m a c h i n e c r e a t e - d v i r t u a l b o x a g e n t 2 $ d o c k e r - m a c h i n e l s N A M E A C T I V E D R I V E R S T A T E U R L S W A R M D O C K E R a g e n t 1 - v i r t u a l b o x R u n n i n g t c p : / / 1 9 2 . 1 6 8 . 9 9 . 1 0 1 : 2 3 7 6 v 1 . 1 1 . 1 a g e n t 2 - v i r t u a l b o x R u n n i n g t c p : / / 1 9 2 . 1 6 8 . 9 9 . 1 0 2 : 2 3 7 6 v 1 . 1 1 . 1 d e f a u l t - v i r t u a l b o x S t o p p e d U n k n o w n m a n a g e r - v i r t u a l b o x R u n n i n g t c p : / / 1 9 2 . 1 6 8 . 9 9 . 1 0 0 : 2 3 7 6 v 1 . 1 1 . 1 23 / 31 Create Nodes
  13. $ e v a l $ ( d o c

    k e r - m a c h i n e e n v m a n a g e r ) $ d o c k e r r u n - - r m s w a r m c r e a t e U n a b l e t o f i n d i m a g e ' s w a r m : l a t e s t ' l o c a l l y l a t e s t : P u l l i n g f r o m l i b r a r y / s w a r m d d 2 c a 0 2 f e e e f : P u l l c o m p l e t e . . . a 3 e d 9 5 c a e b 0 2 : P u l l c o m p l e t e D i g e s t : s h a 2 5 6 : 6 9 3 6 3 2 7 2 4 4 3 f 4 0 8 0 e 0 6 2 3 e 7 8 c e d 4 1 b f 3 8 2 7 3 5 3 5 e e 7 f 4 2 2 b 2 6 b b c 5 5 5 d b 2 b 5 d 4 a 4 S t a t u s : D o w n l o a d e d n e w e r i m a g e f o r s w a r m : l a t e s t 3 2 3 5 1 7 c d 6 2 f 3 b 9 6 9 7 1 5 2 e 0 9 b d c f e 8 7 1 4 $ 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 S T A T U S $ d o c k e r i m a g e s R E P O S I T O R Y T A G I M A G E I D C R E A T E D S I Z E s w a r m l a t e s t 4 7 d c 1 8 2 e a 7 4 b 3 2 h o u r s a g o 1 9 . 3 2 $ d o c k e r r u n - d - p 3 3 7 6 : 3 3 7 6 - t - v / v a r / l i b / b o o t 2 d o c k e r : / c e r t s : r o s w a r m m a n a g e - H 0 . 0 . 2 0 8 2 4 6 4 9 f d 0 3 3 5 1 d a 2 f 8 b 7 7 2 7 0 3 3 2 c 2 d 9 4 9 8 3 6 6 4 a 7 a 2 7 3 3 a 7 7 6 d 4 8 b 6 4 b 4 0 9 6 5 5 24 / 31 Run Swarm Manager
  14. In this case, we are using the discovery backend hosted

    on Docker Hub to create a unique discovery token for the cluster. This discovery backend is only for low-volume development and testing purposes. The discovery backend maintains an up-to- date list of cluster members and shares that list with the Swarm manager. The Swarm manager uses this list to assign tasks to the nodes. 25 / 31 Swarm Discovery Token
  15. $ e v a l $ ( d o c

    k e r - m a c h i n e e n v a g e n t 1 ) $ d o c k e r r u n - d s w a r m j o i n - - a d d r = $ ( d o c k e r - m a c h i n e i p a g e n t 1 ) : 2 3 7 6 t o k e n : / / 3 2 3 5 1 7 c d 6 2 f 3 b U n a b l e t o f i n d i m a g e ' s w a r m : l a t e s t ' l o c a l l y l a t e s t : P u l l i n g f r o m l i b r a r y / s w a r m d d 2 c a 0 2 f e e e f : P u l l c o m p l e t e . . . a 3 e d 9 5 c a e b 0 2 : P u l l c o m p l e t e D i g e s t : s h a 2 5 6 : 6 9 3 6 3 2 7 2 4 4 3 f 4 0 8 0 e 0 6 2 3 e 7 8 c e d 4 1 b f 3 8 2 7 3 5 3 5 e e 7 f 4 2 2 b 2 6 b b c 5 5 5 d b 2 b 5 d 4 a 4 S t a t u s : D o w n l o a d e d n e w e r i m a g e f o r s w a r m : l a t e s t 2 f 9 2 9 c d f f 3 e 9 a e 6 d e 4 7 b 0 3 6 7 1 4 0 b d c 3 e 0 f 2 d 2 3 d 8 e f 8 0 9 d 4 b b 5 f 8 9 0 0 f f b a 8 2 e 6 3 $ e v a l $ ( d o c k e r - m a c h i n e e n v a g e n t 2 ) $ d o c k e r r u n - d s w a r m j o i n - - a d d r = $ ( d o c k e r - m a c h i n e i p a g e n t 2 ) : 2 3 7 6 t o k e n : / / 3 2 3 5 1 7 c d 6 2 f 3 b . . . $ e v a l $ ( d o c k e r - m a c h i n e e n v - u ) 26 / 31 Run Swarm Agents
  16. $ e v a l $ ( d o c

    k e r - m a c h i n e e n v m a n a g e r ) $ e x p o r t D O C K E R _ H O S T = $ ( d o c k e r - m a c h i n e i p m a n a g e r ) : 3 3 7 6 $ d o c k e r i n f o C o n t a i n e r s : 2 R u n n i n g : 2 P a u s e d : 0 S t o p p e d : 0 I m a g e s : 2 S e r v e r V e r s i o n : s w a r m / 1 . 2 . 1 R o l e : p r i m a r y S t r a t e g y : s p r e a d F i l t e r s : h e a l t h , p o r t , c o n t a i n e r s l o t s , d e p e n d e n c y , a f f i n i t y , c o n s t r a i n t N o d e s : 2 a g e n t 1 : 1 9 2 . 1 6 8 . 9 9 . 1 0 1 : 2 3 7 6 - C o n t a i n e r s : 1 - R e s e r v e d C P U s : 0 / 1 - R e s e r v e d M e m o r y : 0 B / 1 . 0 2 1 G i B a g e n t 2 : 1 9 2 . 1 6 8 . 9 9 . 1 0 2 : 2 3 7 6 - C o n t a i n e r s : 1 - R e s e r v e d C P U s : 0 / 1 - R e s e r v e d M e m o r y : 0 B / 1 . 0 2 1 G i B . . . K e r n e l V e r s i o n : 4 . 4 . 8 - b o o t 2 d o c k e r O p e r a t i n g S y s t e m : l i n u x A r c h i t e c t u r e : a m d 6 4 C P U s : 2 T o t a l M e m o r y : 2 . 0 4 2 G i B . . . W A R N I N G : N o k e r n e l m e m o r y l i m i t s u p p o r t 27 / 31 Connect to Swarm
  17. $ d o c k e r r u n

    h e l l o - w o r l d H e l l o f r o m D o c k e r . . . . $ d o c k e r p s - a 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 S T A 8 1 e a 3 6 6 b 4 6 e 5 h e l l o - w o r l d " / h e l l o " 1 8 s e c o n d s a g o E x i a b b f b c c 8 d e 6 2 s w a r m " / s w a r m j o i n - - a d d r = 1 " 2 0 m i n u t e s a g o U p 2 f 9 2 9 c d f f 3 e 9 s w a r m " / s w a r m j o i n - - a d d r = 1 " 2 2 m i n u t e s a g o U p 28 / 31 Use Swarm
  18. Refs 1. Machine Overview 2. Get started with a local

    VM 3. Swarm Overview 4. Evaluate Swarm in a sandbox 5. Mike Goelzer, Swarm: Docker Native Clustering 6. Docker Machine - Reference env 30 / 31