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

Docker for Development Environments

Docker for Development Environments

Managing development environments with docker-compose.

Avatar for Joshua Gardner

Joshua Gardner

May 08, 2015
Tweet

More Decks by Joshua Gardner

Other Decks in Programming

Transcript

  1. Try­It Server: s s h d o c k e

    r @ 1 0 7 . 1 7 0 . 2 5 3 . 2 0 3 Password o p e n w e s t 2 0 1 5 SET SAIL WITH DOCKER DOCKER FOR DEVELOPMENT ENVIRONMENTS Presented on May 8th, 2015 at by . OpenWest Conference Joshua Gardner
  2. AUTOMATED, ISOLATED DEVELOPMENT ENVIRONMENTS These are a Good Thing™! Allows

    your developers to focus on code, not on the dirty details of devilish daemons and decoding documentation and design of their devices.
  3. DOCKER IS GREAT FOR DEVELOPMENT Docker is the Container Engine

    for Linux. ADVANTAGES: Strong Isolation Speed Repeatability: Images and Dockerfiles Composable Simulates a Production Environment FORGET “IT WORKS ON MY MACHINE.”
  4. DIVE IN TO DOCKER Installation instructions are at . Docker

    can be used on all recent Linux distributions, and in combination with VirtualBox on Mac OS X and Windows. Docker.com c u r l h t t p s : / / g e t . d o c k e r . c o m / | s h D O C K E R - C O M P O S E p i p 2 i n s t a l l ­ ­ u s e r ­ ­ u p g r a d e d o c k e r ­ c o m p o s e
  5. TRY IT WITH SSH s s h d o c

    k e r @ 1 0 7 . 1 7 0 . 2 5 3 . 2 0 3
  6. DOCKER BASICS Docker runs containers based on images. Images are

    templates for containers. How to make images: Download from a registry From a container From a D o c k e r f i l e Containers are created with d o c k e r r u n .
  7. FIRST STEPS WITH DOCKER Having installed Docker or using the

    provided SSH account: d o c k e r p u l l u b u n t u : 1 4 . 0 4 d o c k e r r u n u b u n t u : 1 4 . 0 4 e c h o ' h e l l o , d o c k e r ! ' This creates a container that runs the e c h o command. When the command exits the container exits but still exists. d o c k e r p s ­ a
  8. To remove the stopped instance: d o c k e

    r r m h a p p y _ h e i s e n b e r g You can use either part of the SHA ID of the container or the randomly assigned name which has the form “adjective_scientist”.
  9. To create in interactive session: d o c k e

    r r u n ­ ­ r m ­ i t u b u n t u : 1 4 . 0 4 / b i n / b a s h
  10. BUILDING IMAGES WITH DOCKERFILES D o c k e r

    f i l e is a language used by Docker to build new images. It takes a base image, runs some commands within that image, and creates a new image.
  11. AN EXAMPLE DOCKERFILE F R O M p y t

    h o n : 3 . 4 A D D . / c o d e W O R K D I R / c o d e R U N p i p i n s t a l l ­ r r e q u i r e m e n t s . t x t R U N p i p i n s t a l l u w s g i E X P O S E 8 0 0 0 C M D [ " u w s g i " , " ­ ­ h t t p " , " : 8 0 0 0 " , " ­ ­ w s g i ­ f i l e " , " / c o d e / w s g i . p y " ] With Dockerfile named "Dockerfile" and in directory with files "requirements.txt" and "wsgi.py", run build: d o c k e r b u i l d ­ t m y ­ w s g i ­ a p p .
  12. MANAGING MULTIPLE DOCKERFILES AND CONTAINERS The tool is called d

    o c k e r - c o m p o s e and is an orchestration tool for Docker in a development environment.
  13. Create a new directory, "project", with a subdirectory "app". m

    k d i r ­ p p r o j e c t / a p p c d p r o j e c t
  14. Let's make a very bare basic Python web app in

    "app". v i m a p p / a p p . p y a p p / r e q u i r e m e n t s . t x t Or use whatever editor you like. The SSH server also has nano and emacs.
  15. app.py file # ! / u s r / b

    i n / e n v p y t h o n 3 f r o m f l a s k i m p o r t F l a s k f r o m r e d i s i m p o r t R e d i s a p p = F l a s k ( _ _ n a m e _ _ ) r e d i s = R e d i s ( h o s t = ' r e d i s ' , p o r t = 6 3 7 9 ) @ a p p . r o u t e ( ' / ' ) d e f h e l l o ( ) : r e d i s . i n c r ( ' h i t s ' ) r e t u r n ' H e l l o W o r l d ! I h a v e b e e n s e e n { } t i m e s . \ n ' . f o r m a t ( i n t ( r e d i s . g e t ( ' h i t s ' ) ) ) i f _ _ n a m e _ _ = = " _ _ m a i n _ _ " : a p p . r u n ( h o s t = " 0 . 0 . 0 . 0 " , d e b u g = T r u e )
  16. Now make a Dockerfile in the app directory. v i

    m a p p / D o c k e r f i l e DOCKERFILE F R O M p y t h o n : 3 . 4 A D D . / c o d e W O R K D I R / c o d e R U N p i p i n s t a l l ­ r r e q u i r e m e n t s . t x t E X P O S E 5 0 0 0 C M D [ " p y t h o n " , " a p p . p y " ]
  17. Wrap it all together with a d o c k

    e r - c o m p o s e . y m l file: v i m d o c k e r ­ c o m p o s e . y m l DOCKER-COMPOSE.YML w e b : b u i l d : a p p / c o m m a n d : p y t h o n a p p . p y v o l u m e s : ­ " . / a p p / : / c o d e " p o r t s : ­ " 5 0 0 0 : 5 0 0 0 " l i n k s : ­ r e d i s r e d i s : i m a g e : r e d i s
  18. A more advanced docker-compose.yml file d b : i m

    a g e : p o s t g r e s : l a t e s t v o l u m e s : ­ " . : / c o d e " d s e : b u i l d : d s e / c o m m a n d : / b i n / t r u e c a s s a n d r a A : i m a g e : a c m e _ d s e v o l u m e s : ­ " . / c a s s a n d r a A / d a t a : / v a r / l i b / c a s s a n d r a " ­ " . / c a s s a n d r a A / l o g : / v a r / l o g / c a s s a n d r a " ­ " . / c a s s a n d r a A / s p a r k d : / v a r / l i b / s p a r k " ­ " . / c a s s a n d r a A / s p a r k l : / v a r / l o g / s p a r k " c o m m a n d : c a s s a n d r a p o r t s :
  19. DOCKER IS GREAT FOR DEVELOPMENT With docker-compose, complex development environments

    can be made portable and repeatable. Perfect for Service Oriented Architecture or any other project with many networked components.