docker 101 - from production to development

15
Docker 101 From production to development Raül Pérez <[email protected]>

Upload: rauel-perez

Post on 13-Apr-2017

202 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Docker 101 - From production to development

Docker 101From production to development

Raül Pérez <[email protected]>

Page 2: Docker 101 - From production to development

Who am I?Raül Pérez

@repejota

https://github.com/repejota

https://www.linkedin.com/in/repejota

Lead Software Engineer at @Carrenza

● Managing a small team remotely from Barcelona.

● Working with DevOPS stuff.● Still more a dev than an OP.● Proud to be a #Gopher but I’ve

coded on a bunch of different languages.

Raül Pérez 20/01/2016

Page 3: Docker 101 - From production to development

What is Docker?Docker is a tool:

● Based on the original LXC. ● Helps you to containerize your app.● Handles network between

containers.● Handles volumes between

containers.

Raül Pérez 20/01/2016

Page 4: Docker 101 - From production to development

What is not Docker?● Docker are not Virtual Machines!!● Docker does not offer a single way

to do things:○ Offers a powerful CLI

○ There is always more than one way to do the same.

○ Build workflows, adapt it to your existing pipeline.

Raül Pérez 20/01/2016

Page 5: Docker 101 - From production to development

Docker: Many tools in onedocker

● Main tool.● Handles containers.

docker-compose

● Orchestrate containers.

docker-machine

● Manage servers ( remote or local ).

Raül Pérez 20/01/2016

Page 6: Docker 101 - From production to development

Docker: docker● Handles building containers.● Handles building images.● Handles running containers.● ....

● It does not orchestrate.● It does not help during the

development process.

Raül Pérez 20/01/2016

Page 7: Docker 101 - From production to development

Docker: docker-compose● It orchestrates containers.● Handles show each container

connects to other ones.

Raül Pérez 20/01/2016

Page 8: Docker 101 - From production to development

Docker: docker-machine● Manages remote servers● Manages virtual machines (

Vagrant )

Raül Pérez 20/01/2016

Page 9: Docker 101 - From production to development

How to use Docker?Production:

● Uses images● hub.docker.com● Everything is built.● Everything is compiled.● EASY!

Development:

● Uses the code itself.● Nothing is build or compiled.● HARD!

https://github.com/hurrabox

Raül Pérez 20/01/2016

Page 10: Docker 101 - From production to development

How to use Docker? : production● docker-compose.yml● 5 containers

○ database○ redis○ api○ front

○ nginx

● This is for production○ It builds from images

db:

image: postgres

redis:

image: redis

api:

restart: always

image: ulabox/api:latest

links: - redis

- db

front:

restart: always

image: ulabox/front:latest

links:

- redis

- db

nginx:

restart: always

image: ulabox/nginx:latest

ports:

- "80:80"

links:

- front

- api

Raül Pérez 20/01/2016

Page 11: Docker 101 - From production to development

How to use Docker? : development● docker-compose-dev.yml● 5 containers

○ database○ redis○ api○ front○ nginx

● This is for development○ It builds from source code

api:

build: ./repos/api

volumes:

- ./repos/api:/src

front:

build: ./repos/front

volumes:

- ./repos/front:/src

nginx:

build: ./repos/nginx

volumes:

- ./nginx/conf.d:/etc/nginx/conf.d

Raül Pérez 20/01/2016

Page 12: Docker 101 - From production to development

How to use Docker?docker-compose -f docker-compose.yml -f dev.yml up -d

● Uses docker composition of services https://docs.docker.com/compose/extends/

● First use docker-compose.yml ● Second ‘extend’ the service overriding fields with dev.yml

● Do not worry anymore about how to link prod & dev, you just got it. :)

Raül Pérez 20/01/2016

Page 13: Docker 101 - From production to development

How to use Docker? Workflow● Yes but, how do i work on a

component of my service?○ Do I need a shared folder?○ Do I need to ssh to to the container?○ How can i change/build/restart?

● Well there is no a perfect solution for this … yet.

Raül Pérez 20/01/2016

Page 14: Docker 101 - From production to development

How to use Docker?docker-compose -f docker-compose.yml -f dev.yml run <service> <cmd> --service-ports

● Service ports allows you to read dependencies and start the related containers of the one you choose.

● It executes also CMD overriding the default command. ● You can use it like the normal docker CLI to start a container and expose a

path as a volume.

Raül Pérez 20/01/2016

Page 15: Docker 101 - From production to development

Thanks!Questions?