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

Improve Docker Image by BuildKit

go_vargo
July 05, 2019

Improve Docker Image by BuildKit

go_vargo

July 05, 2019
Tweet

More Decks by go_vargo

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ ໊લ: ү ݡେ(@go_vargo) ॴଐ: גࣜձࣾίϩϓϥ ɹɹ Πϯϑϥάϧʔϓ ୈ2νʔϜ झຯ:

    Ϋϥ΢υωΠςΟϒܥͷMeetup΁ͷࢀՃ ࠷ۙͷ೰Έ͸ɺίϯςφϫʔΫϩʔυͷҋ΁ͷ ཱͪ޲͔͍ํ 2
  2. 9 ᶄ ؀ڥࠩ෼ΛεςʔδԽ मਖ਼લ मਖ਼ޙ Dockerfile.local Debugger Git Vim …

    Dockerfile.k8s FROM image AS local …. FROM image AS local debug …. FROM image AS k8s …. FROM image AS k8s-XXXX …. ҰͭͷϑΝΠϧʹू໿͢Δ͜ͱͰɺ ίʔυͷڞ௨ԽͱՄಡੑΛߴΊΔ Dockerfile.xxxx …
  3. 11 मਖ਼લ FROM php:7.2.18-alpine COPY docker/files / COPY composer.json composer.lock

    /app/ RUN cd /app \ && apk add --no-cache --virtual .build-deps zip unzip git \ && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer \ && composer global require hirak/prestissimo \ && composer install --prefer-dist --no-interaction --no-scripts --no-autoloader --no-dev \ && chown -R www-data:www-data vendor \ && find vendor/ -type d -name ‘.git’ -print0 | xargs -0 rm -rf \ && apk del .build-deps \ && composer global remove hirak/prestissimo \ && rm -rf /root/.composer/ COPY --chown=www-data:www-data . /app WORKDIR /app CMD [“run”] ᶄ ؀ڥࠩ෼ΛεςʔδԽ ىಈεΫϦϓτΛίϐʔ ύοέʔδ؅ཧͷϑΝΠϧΛίϐʔ ϥΠϒϥϦ΍ύοέʔδ؅ཧπʔϧΛΠϯετʔϧ ιʔείʔυΛίϐʔ
  4. 12 ##### ComposerΠϯετʔϧ༻ ##### FROM php:7.2.18-alpine AS builder COPY composer.json

    composer.lock /app/ WORKDIR /app RUN cd /app \ && apk add --no-cache --virtual .build-deps zip unzip git \ && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer \ && composer global require hirak/prestissimo \ && composer install --prefer-dist --no-interaction --no-scripts --no-autoloader —no-dev ##### Kubernetes༻Πϝʔδ ##### FROM php:7.2.18-alpine AS k8s COPY docker/files / WORKDIR /app COPY --chown=www-data:www-data . /app/ COPY --from= builder /usr/local/bin/composer /usr/local/bin/composer RUN apk add —no-cache zip unzip COPY --from=builder --chown=www-data:www-data /app/vendor /app/vendor CMD [“run”] मਖ਼ޙ - v1 ىಈεΫϦϓτΛίϐʔ ύοέʔδ؅ཧͷϑΝΠϧΛίϐʔ ύοέʔδΛΠϯετʔϧ ੒Ռ෺Λίϐʔ ύοέʔδϚωʔδϟΛίϐʔ
  5. 13 ##### ComposerΠϯετʔϧ༻ ##### FROM php:7.2.18-alpine AS builder COPY composer.json

    composer.lock /app/ WORKDIR /app RUN cd /app \ && apk add --no-cache --virtual .build-deps zip unzip git \ && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer \ && composer global require hirak/prestissimo \ && composer install --prefer-dist --no-interaction --no-scripts --no-autoloader —no-dev ##### Kubernetes༻Πϝʔδ ##### FROM php:7.2.18-alpine AS k8s COPY docker/files / WORKDIR /app COPY --chown=www-data:www-data . /app/ COPY --from= builder /usr/local/bin/composer /usr/local/bin/composer RUN apk add —no-cache zip unzip COPY --from=builder --chown=www-data:www-data /app/vendor /app/vendor CMD [“run”] मਖ਼ޙ - v1 ‑ύοέʔδϚωʔδϟͷΠϯετʔϧ͸ຖճ࣮ߦ͢Δඞཁͳ͠
  6. 14 ##### ComposerΠϯετʔϧ༻ ##### FROM composer:1.8.6 AS builder COPY composer.json

    composer.lock /app/ WORKDIR /app RUN composer global require hirak/prestissimo \ && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer \ && composer install --prefer-dist --no-interaction --no-scripts --no-autoloader --no-dev \ && chown -R www-data:www-data vendor \ && find vendor/ -type d -name ‘.git’ -print0 | xargs -0 rm -rf ##### Kubernetes༻Πϝʔδ ##### FROM php:7.2.18-alpine AS k8s COPY docker/files / WORKDIR /app COPY --chown=www-data:www-data . /app/ COPY --from=builder /usr/local/bin/composer /usr/local/bin/composer RUN apk add —no-cache zip unzip COPY --from=builder --chown=www-data:www-data /app/vendor /app/vendor CMD [“run”] मਖ਼ޙ - v2 ผͷΠϝʔδͱͯ͠੾Γग़͢ Πϯετʔϧ෦෼͸࡟আ
  7. 15 ##### ComposerΠϯετʔϧ༻ ##### FROM composer:1.8.6 AS builder COPY composer.json

    composer.lock /app/ WORKDIR /app RUN composer global require hirak/prestissimo \ && composer install --prefer-dist --no-interaction --no-scripts --no-autoloader --no-dev \ && chown -R www-data:www-data vendor \ && find vendor/ -type d -name ‘.git’ -print0 | xargs -0 rm -rf ##### Kubernetes༻Πϝʔδ ##### FROM php:7.2.18-alpine AS k8s COPY docker/files / WORKDIR /app COPY --chown=www-data:www-data . /app/ COPY --from=builder /usr/local/bin/composer /usr/local/bin/composer RUN apk add —no-cache zip unzip COPY --from=builder --chown=www-data:www-data /app/vendor /app/vendor CMD [“run”] मਖ਼ޙ - v2 ‏builderͷ଴ͪ߹Θ͕ͤൃੜ
  8. 16 ##### Composerίϐʔ༻ ##### FROM composer:1.8.6 AS copy ##### ComposerΠϯετʔϧ༻

    ##### FROM composer:1.8.6 AS builder COPY composer.json composer.lock /app/ WORKDIR /app RUN composer global require hirak/prestissimo \ && composer install --prefer-dist --no-interaction --no-scripts --no-autoloader --no-dev \ && chown -R www-data:www-data vendor \ && find vendor/ -type d -name ‘.git’ -print0 | xargs -0 rm -rf ##### Kubernetes༻Πϝʔδ ##### FROM php:7.2.18-alpine AS k8s COPY docker/files / WORKDIR /app COPY --chown=www-data:www-data . /app/ COPY --from=copy /usr/local/bin/composer /usr/local/bin/composer RUN apk add —no-cache zip unzip COPY --from=builder --chown=www-data:www-data /app/vendor /app/vendor मਖ਼ޙ - v3 ‏଴ͪ߹ΘͤΛճආ ‏͜͜͸଴ͪ߹Θͤ
  9. 20 վળ݁Ռ ϩʔΧϧ༻Πϝʔδ मਖ਼લ मਖ਼ޙ αΠζ 357MB 355MB Ϗϧυ࣌ؒ(1ճ) 88s

    41s Ϗϧυ࣌ؒ(2ճ໨Ҏ߱) 12s 2s K8s༻Πϝʔδ मਖ਼લ मਖ਼ޙ αΠζ 209MB 209MB Ϗϧυ࣌ؒ(1ճ) 78s 41s Ϗϧυ࣌ؒ(2ճ໨Ҏ߱) 16s 2s