Docker e Docker-Compose

Juliano Marcon














Quem sou eu?

Especialista em Arquitetura de Soluções

Formado em Matemática pela UNESP

Apaixonado por tecnologia

Developer!!!

Docker

Na minha máquina funciona!

Novamente :-)

https://docs.docker.com/engine/installation/linux/

Docker no macOS e Windows!

macOS 10.10.3 (Yosemite) ou maior
Windows 10 Pro 64bit build 10586 ou maior
+ Hyper-V instalado

Dockerfile


FROM nginx:1.10-alpine
COPY apresentacao/ /usr/share/nginx/html
CMD nginx -g 'daemon off;'
						

Demo

Não instale pacotes desnecessários

O limite de camadas subiu de 42 para 127!

Utilize tags

docker build . -t tag:version

O que mais muda
fica para o final!

apt-get


FROM ubuntu
RUN apt-get update
RUN apt-get install wget
                            

FROM ubuntu
RUN apt-get update
RUN apt-get install wget vim
                            

FROM ubuntu
RUN apt-get update && apt-get install wget vim
                            

Docker Machine


$ docker-machine create -d virtualbox nomedohost

Creating CA: /home/username/.docker/machine/certs/ca.pem
Creating client certificate: /home/username/.docker/machine/certs/cert.pem
Image cache does not exist, creating it at /home/username/.docker/machine/cache...
No default boot2docker iso found locally, downloading the latest release...
Downloading https://github.com/boot2docker/boot2docker/releases/download/v1.6.2/boot2docker.iso to /home/username/.docker/machine/cache/boot2docker.iso...
Creating VirtualBox VM...
Creating SSH key...
Starting VirtualBox VM...
Starting VM...
To see how to connect Docker to this machine, run: docker-machine env nomedohost

$ eval "$(docker-machine env nomedohost)"

$ eval "$(docker-machine env -u)"
						

$ docker-machine create --driver digitalocean 
--digitalocean-access-token $dotoken devmesh-now

Running pre-create checks...
Creating machine...
(devmesh-now) Creating SSH key...
(devmesh-now) Creating Digital Ocean droplet...
(devmesh-now) Waiting for IP address to be assigned to the Droplet...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with ubuntu(systemd)...
Installing Docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client 
to the Docker Engine running on this virtual machine, 
run: docker-machine env devmesh-now
						

$ docker-machine env devmesh-now

export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://45.55.66.73:2376"
export DOCKER_CERT_PATH="/Users/jmarcon/.docker/machine/machines/devmesh-now"
export DOCKER_MACHINE_NAME="devmesh-now"
# Run this command to configure your shell:
# eval $(docker-machine env devmesh-now)
						


$ docker build . -t apresentacao:latest

Sending build context to Docker daemon  35.1 MB
Step 1 : FROM nginx:1.10-alpine
1.10-alpine: Pulling from library/nginx

3690ec4760f9: Pull complete
2e2cf600c52c: Pull complete
3302770f2bf7: Pull complete
e97f47e49acb: Pull complete
Digest: sha256:56766e6df28bb0c572dca24acbe5639ddf866d931c105cb33410d52624c27682
Status: Downloaded newer image for nginx:1.10-alpine
 ---> 501d2ca4f2e2
Step 2 : COPY . /usr/share/nginx/html
 ---> 0cd1f68842d0
Removing intermediate container aa7281676c85
Step 3 : CMD nginx -g 'daemon off;'
 ---> Running in c6502ff53f16
 ---> 50a2bdfd7c9d
Removing intermediate container c6502ff53f16
Successfully built 50a2bdfd7c9d
                        

Demo

macOS 10.8.3 (Montain Lion) ou maior
Windows 7 64bit ou maior
+ virtualização

Docker-Compose

Ferramenta para definir e executar aplicações em multiplos containers Docker.










Demo

12 fatores

  • Codebase
  • Dependências
  • Configurações
  • Serviços de Apoio
  • Build, Release, Run
  • Processos
  • Vinculo de Porta
  • Concorrência
  • Descartabilidade
  • Dev/Prod semelhantes
  • Logs
  • Processos de Admin

E mais...
  • Monitoração
  • Autenticação e Autorização
  • API First

https://12factor.net/

  • Segurança dos repositórios das imagens
  • Orquestração do processo de deploy dos containers com zero downtime
  • Roll-back do deploy de containers
  • Rede entre os containers entre vários hosts
  • Gerenciar os logs dos containers
  • Gerenciar os dados em containers (DB)
  • Criar imagens que lidem corretamente com init, logs, etc.
  • Muito, muito mais...

Obrigado!

http://www.julianomarcon.com.br
http://www.linkedin.com/in/julianomarcon
@julianomarcon
“Learn the rules like a pro, so you can break them like an artist."

Pablo Picasso

  • Reveal.js
  • JQuery