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

[SPARCS TeaParty] Alpine Linux and Docker

[SPARCS TeaParty] Alpine Linux and Docker

Joongi Kim

April 23, 2017
Tweet

More Decks by Joongi Kim

Other Decks in Programming

Transcript

  1. Reference Image Sizes (compressed) Image Size ubuntu:16.04 46 MB alpine:3.5

    1.8 MB python:3.6 266 MB python:3.6-slim 76 MB python:3.6-alpine 29 MB
  2. Impact of Large Image Sizes in Docker • Increased registry

    push/pull 4me • Increased disk usage • CPU/RAM usage at run4me? – No public benchmarks yet
  3. How light-weight? • Minimal root filesystem tarball (gzipped): 1.9 MB

    • Standalone version incl. kernel (iso): 81.8 MB How possible? • musl libc: 4.7 MB (GNU libc 26.3 MB), both gzipped • BusyBox: 873 KB (incl. common Linux commands and a shell)
  4. Common Dockerfile Pa/ern FROM ubuntu:16.04 RUN apt-get update RUN apt-get

    install build-essential RUN wget seomthing.tar.gz WORKDIR something RUN make && make install RUN apt-get remove build-essential Q. What's the problem here?
  5. Common Technique to Reduce Size FROM ubuntu:16.04 RUN apt-get update

    RUN apt-get install build-essential && \ wget something.tar.gz && \ cd something && \ make && make install && \ apt-get remove build-essential
  6. With Alpine Linux FROM alpine:3.5 RUN apk add --no-cache --virtual

    .build-deps build-base wget something.tar.gz && \ cd something && \ make && make install && \ apk del .build-deps • No repository index remaining • Clean removal of all depedent packages inside virtual package namespace
  7. Op#miza#on Result Image Before3 A,er kernel-python3 4 1.44 GB 620

    MB kernel-nodejs6 568 MB 62 MB kernel-php7 571 MB 48 MB kernel-lua5 408 MB 166 MB 4 Includes numpy, matplotlib, scipy, pandas, scikit-learn, ... 3 Not op'mized at all; just apt-get install-ed every dependencies
  8. Caveat • musl libc s*cks strictly to standard APIs •

    Just copying binaries built on Ubuntu is not likely to work! • ldd (and Google) is your friend! # ldd /usr/bin/influx /lib64/ld-linux-x86-64.so.2 (0x55fc22b32000) libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x55fc22b32000) libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x55fc22b32000) Error relocating /usr/bin/influx: __vfprintf_chk: symbol not found
  9. Docker's Counter-A0ack • docker build --squash (since v1.13) • Squashes

    all layers into a single layer a9er build • Preserves intermediate layers for build-cache locally (not published to registry) • MulB-stage builds (will be introduced in v17.05) • MulBple FROM statements in Dockerfile • Can copy files generated in former FROM stage containers