Slide 1

Slide 1 text

Docker Multi Stage Builds Human Talks Grenoble octobre 2017 | @_crev_

Slide 2

Slide 2 text

Human Talks Grenoble octobre 2017 | @_crev_

Slide 3

Slide 3 text

- Images plus légères - Unique fichier de build Human Talks Grenoble octobre 2017 | @_crev_

Slide 4

Slide 4 text

Pourquoi plus légères Human Talks Grenoble octobre 2017 | @_crev_

Slide 5

Slide 5 text

push, pull, run Human Talks Grenoble octobre 2017 | @_crev_

Slide 6

Slide 6 text

container != virtualisation légère Human Talks Grenoble octobre 2017 | @_crev_

Slide 7

Slide 7 text

Étapes de fabrication : Compilation des dépendances Traitements intermédiaires Image cible Human Talks Grenoble octobre 2017 | @_crev_

Slide 8

Slide 8 text

Examples Human Talks Grenoble octobre 2017 | @_crev_

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Simple Docker FROM golang WORKDIR /go/src/app COPY . . RUN go-wrapper download RUN go-wrapper install CMD ["go-wrapper", "run"] 737MB Human Talks Grenoble octobre 2017 | @_crev_

Slide 11

Slide 11 text

Pattern Builder FROM golang WORKDIR /go/src/ht_docker_multi_stage COPY . . RUN go-wrapper download CMD ["go", "build", "-v"] FROM gcr.io/distroless/base COPY ht_docker_multi_stage / CMD ["/ht_docker_multi_stage"] Human Talks Grenoble octobre 2017 | @_crev_

Slide 12

Slide 12 text

Pattern Builder (2) build: docker build -t ht_build_and_package-builder -f Dockerfile.build . docker run --rm -v $$PWD:/go/src/ht_docker_multi_stage \ ht_build_and_package-builder 17.5MB Human Talks Grenoble octobre 2017 | @_crev_

Slide 13

Slide 13 text

Multi Stage FROM golang as builder WORKDIR /go/src/ht_docker_multi_stage COPY . . RUN go-wrapper download RUN go-wrapper install FROM gcr.io/distroless/base COPY --from=builder /go/bin/ht_docker_multi_stage / CMD ["/ht_docker_multi_stage"] 17.5MB Human Talks Grenoble octobre 2017 | @_crev_

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

NGinx FROM nginx:1.13-alpine EXPOSE 80 COPY conf/default.conf /etc/nginx/conf.d/default.conf COPY build/ /usr/share/nginx/html Human Talks Grenoble octobre 2017 | @_crev_

Slide 16

Slide 16 text

React build FROM node:8-alpine as dependencies WORKDIR /usr/src/app COPY package.json yarn.lock /usr/src/app/ RUN yarn install FROM node:8-alpine as builder WORKDIR /usr/src/app COPY . . COPY --from=dependencies /usr/src/app/node_modules /usr/src/app/node_modules RUN yarn build FROM nginx:1.13-alpine EXPOSE 80 COPY conf/default.conf /etc/nginx/conf.d/default.conf COPY --from=builder /usr/src/app/build/ /usr/share/nginx/html Human Talks Grenoble octobre 2017 | @_crev_

Slide 17

Slide 17 text

Sass build FROM ruby:2-alpine3.6 as sass RUN apk add --no-cache --virtual build-dep build-base \ && gem install sass --no-doc \ && apk del build-dep && rm -rf /var/cache/apk/* COPY scss /usr/src/app WORKDIR /usr/src/app RUN sass bootstrap.scss > App.css #... FROM node:8-alpine as builder WORKDIR /usr/src/app COPY . . COPY --from=dependencies /usr/src/app/node_modules /usr/src/app/node_modules COPY --from=sass /usr/src/app/App.css /usr/src/app/src/App.css RUN yarn build Human Talks Grenoble octobre 2017 | @_crev_

Slide 18

Slide 18 text

Limites Human Talks Grenoble octobre 2017 | @_crev_

Slide 19

Slide 19 text

Limites Pas de partage de stag Linter pas à jour Docker >= 17.05 Human Talks Grenoble octobre 2017 | @_crev_

Slide 20

Slide 20 text

Limites Pas de partage de stag Comment partager dependencie entre container de dev et container intermédiaire de prod ? Partage de step au travers du cache docker ? Génération des Dockerfile ? Human Talks Grenoble octobre 2017 | @_crev_

Slide 21

Slide 21 text

Limites Linter pas à jour $ docker run --rm -it --privileged -v $PWD:/root/ \ projectatomic/dockerfile-lint dockerfile_lint lint --------ERRORS--------- Line 1: -> FROM ruby:2-alpine3.6 as sass ERROR: Invalid parameters for command.. Reference -> https://docs.docker.com/engine/reference/builder/ Line 12: -> FROM node:8-alpine as dependencies ERROR: Invalid parameters for command.. Reference -> https://docs.docker.com/engine/reference/builder/ Human Talks Grenoble octobre 2017 | @_crev_

Slide 22

Slide 22 text

Limites Docker >= 17.05 Kubernetes < 1.8 docker <= 1.12 Human Talks Grenoble octobre 2017 | @_crev_

Slide 23

Slide 23 text

Avantages Human Talks Grenoble octobre 2017 | @_crev_

Slide 24

Slide 24 text

Avantages Toute la construction présente dans un unique chier Suppression d'outils de build externes (type Makefile ) docker build + docker run , that's all folks Human Talks Grenoble octobre 2017 | @_crev_

Slide 25

Slide 25 text

Thanks Human Talks Grenoble octobre 2017 | @_crev_ | docker run --rm -it squarescale/ybrissaud