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

Optimizing Docker Images

Optimizing Docker Images

Lightnting talk presented at the Tokyo Docker Meetup #5 http://eventdots.jp/event/567049

Allan Espinosa

August 19, 2015
Tweet

More Decks by Allan Espinosa

Other Decks in Technology

Transcript

  1. Allan Espinosa
    OPTIMIZING DOCKER
    IMAGES
    [email protected]

    View Slide

  2. ABOUT ME
     aespinosa.github.io
     @AllanEspinosa
     aespinosa
    Docker High Performance

    View Slide

  3. AGENDA
    Why Optimize
    Caching deployments
    Lean Docker images
    Caching Docker builds
    Conclusion

    View Slide

  4. UNOPTIMIZED
    CONTAINERS
    Slow deployment time
    Slow image build time
    Cancels out Docker's advantages

    View Slide

  5. SLOW DEPLOYMENT
    TIME
    Downloading images
    Large images

    View Slide

  6. SMALL DOCKER
    IMAGES
    Static binaries
    Dynamic binaries

    View Slide

  7. DYNAMIC BINARIES
    F
    R
    O
    M g
    o
    l
    a
    n
    g
    :
    1
    .
    4
    .
    2
    A
    D
    D h
    e
    l
    l
    o
    .
    g
    o h
    e
    l
    l
    o
    .
    g
    o
    R
    U
    N g
    o b
    u
    i
    l
    d h
    e
    l
    l
    o
    .
    g
    o
    E
    X
    P
    O
    S
    E 8
    0
    8
    0
    E
    N
    T
    R
    Y
    P
    O
    I
    N
    T [
    "
    .
    /
    h
    e
    l
    l
    o
    "
    ]

    View Slide

  8. Mostly golang:1.4.2
    R
    E
    P
    O
    S
    I
    T
    O
    R
    Y T
    A
    G .
    .
    . V
    I
    R
    T
    U
    A
    L S
    I
    Z
    E
    l
    a
    r
    g
    e
    a
    p
    p l
    a
    t
    e
    s
    t .
    .
    . 5
    2
    3
    .
    1 M
    B
    g
    o
    l
    a
    n
    g 1
    .
    4
    .
    2 .
    .
    . 5
    1
    7
    .
    3 M
    B

    View Slide

  9. Done! (for static binaries)
    d
    o
    c
    k
    e
    r
    h
    o
    s
    t
    $ d
    o
    c
    k
    e
    r r
    u
    n -
    n
    a
    m
    e b
    u
    i
    l
    t
    a
    p
    p -
    d l
    a
    r
    g
    e
    a
    p
    p
    d
    o
    c
    k
    e
    r
    h
    o
    s
    t
    $ d
    o
    c
    k
    e
    r c
    p b
    u
    i
    l
    t
    a
    p
    p
    :
    /
    h
    e
    l
    l
    o .
    /
    h
    e
    l
    l
    o
    F
    R
    O
    M s
    c
    r
    a
    t
    c
    h
    A
    D
    D h
    e
    l
    l
    o /
    a
    p
    p
    /
    h
    e
    l
    l
    o
    E
    X
    P
    O
    S
    E 8
    0
    8
    0
    E
    N
    T
    R
    Y
    P
    O
    I
    N
    T [
    "
    /
    a
    p
    p
    /
    h
    e
    l
    l
    o
    "
    ]

    View Slide

  10. But on dynamic binaries
    d
    o
    c
    k
    e
    r
    h
    o
    s
    t
    $ d
    o
    c
    k
    e
    r e
    x
    e
    c -
    i
    t b
    u
    i
    l
    t
    a
    p
    p /
    u
    s
    r
    /
    b
    i
    n
    /
    l
    d
    d h
    e
    l
    l
    o
    l
    i
    n
    u
    x
    -
    v
    d
    s
    o
    .
    s
    o
    .
    1 (
    0
    x
    0
    0
    0
    0
    7
    f
    f
    d
    8
    4
    7
    4
    7
    0
    0
    0
    )
    l
    i
    b
    p
    t
    h
    r
    e
    a
    d
    .
    s
    o
    .
    0 =
    > /
    l
    i
    b
    /
    x
    8
    6
    _
    6
    4
    -
    l
    i
    n
    u
    x
    -
    g
    n
    u
    /
    l
    i
    b
    p
    t
    h
    r
    e
    a
    d
    .
    s
    o
    .
    0 (
    0
    x
    0
    0
    0
    0
    7
    f
    3
    2
    f
    l
    i
    b
    c
    .
    s
    o
    .
    6 =
    > /
    l
    i
    b
    /
    x
    8
    6
    _
    6
    4
    -
    l
    i
    n
    u
    x
    -
    g
    n
    u
    /
    l
    i
    b
    c
    .
    s
    o
    .
    6 (
    0
    x
    0
    0
    0
    0
    7
    f
    3
    2
    f
    3
    3
    e
    a
    0
    0
    0
    )
    /
    l
    i
    b
    6
    4
    /
    l
    d
    -
    l
    i
    n
    u
    x
    -
    x
    8
    6
    -
    6
    4
    .
    s
    o
    .
    2 (
    0
    x
    0
    0
    0
    0
    7
    f
    3
    2
    f
    3
    9
    b
    0
    0
    0
    0
    )

    View Slide

  11. Copy them off as well!
    d
    o
    c
    k
    e
    r
    h
    o
    s
    t
    $ d
    o
    c
    k
    e
    r c
    p b
    u
    i
    l
    t
    a
    p
    p
    :
    /
    l
    i
    b
    /
    x
    8
    6
    _
    6
    4
    -
    l
    i
    n
    u
    x
    -
    g
    n
    u
    /
    l
    i
    b
    p
    t
    h
    r
    e
    a
    d
    .
    s
    o
    .
    0 .
    /
    d
    o
    c
    k
    e
    r
    h
    o
    s
    t
    $ d
    o
    c
    k
    e
    r c
    p b
    u
    i
    l
    t
    a
    p
    p
    :
    /
    l
    i
    b
    /
    x
    8
    6
    _
    6
    4
    -
    l
    i
    n
    u
    x
    -
    g
    n
    u
    /
    l
    i
    b
    c
    .
    s
    o
    .
    6 .
    /
    d
    o
    c
    k
    e
    r
    h
    o
    s
    t
    $ d
    o
    c
    k
    e
    r c
    p b
    u
    i
    l
    t
    a
    p
    p
    :
    /
    l
    i
    b
    6
    4
    /
    l
    d
    -
    l
    i
    n
    u
    x
    -
    x
    8
    6
    -
    6
    4
    .
    s
    o
    .
    2 .
    /

    View Slide

  12. F
    R
    O
    M s
    c
    r
    a
    t
    c
    h
    A
    D
    D h
    e
    l
    l
    o /
    a
    p
    p
    /
    h
    e
    l
    l
    o
    A
    D
    D l
    i
    b
    p
    t
    h
    r
    e
    a
    d
    -
    2
    .
    1
    9
    .
    s
    o /
    l
    i
    b
    /
    x
    8
    6
    _
    6
    4
    -
    l
    i
    n
    u
    x
    -
    g
    n
    u
    /
    l
    i
    b
    p
    t
    h
    r
    e
    a
    d
    .
    s
    o
    .
    0
    A
    D
    D l
    i
    b
    c
    -
    2
    .
    1
    9
    .
    s
    o /
    l
    i
    b
    /
    x
    8
    6
    _
    6
    4
    -
    l
    i
    n
    u
    x
    -
    g
    n
    u
    /
    l
    i
    b
    c
    .
    s
    o
    .
    6
    A
    D
    D l
    d
    -
    2
    .
    1
    9
    .
    s
    o /
    l
    i
    b
    6
    4
    /
    l
    d
    -
    l
    i
    n
    u
    x
    -
    x
    8
    6
    -
    6
    4
    .
    s
    o
    .
    2
    E
    X
    P
    O
    S
    E 8
    0
    8
    0
    E
    N
    T
    R
    Y
    P
    O
    I
    N
    T [
    "
    /
    a
    p
    p
    /
    h
    e
    l
    l
    o
    "
    ]

    View Slide

  13. New size of binary image
    R
    E
    P
    O
    S
    I
    T
    O
    R
    Y T
    A
    G .
    .
    . V
    I
    R
    T
    U
    A
    L S
    I
    Z
    E
    b
    i
    n
    a
    r
    y l
    a
    t
    e
    s
    t .
    .
    . 7
    .
    8
    5
    3 M
    B
    l
    a
    r
    g
    e
    a
    p
    p l
    a
    t
    e
    s
    t .
    .
    . 5
    2
    3
    .
    1 M
    B
    g
    o
    l
    a
    n
    g 1
    .
    4
    .
    2 .
    .
    . 5
    1
    7
    .
    3 M
    B

    View Slide

  14. FAST BUILDS
    Caching proxies
    Rearrange Dockerfiles

    View Slide

  15. F
    R
    O
    M r
    u
    b
    y
    :
    2
    .
    2
    .
    2
    A
    D
    D . /
    a
    p
    p
    W
    O
    R
    K
    D
    I
    R /
    a
    p
    p
    R
    U
    N b
    u
    n
    d
    l
    e i
    n
    s
    t
    a
    l
    l
    E
    X
    P
    O
    S
    E 9
    2
    9
    2
    C
    M
    D r
    a
    c
    k
    u
    p -
    E n
    o
    n
    e

    View Slide

  16. bundle install takes forever!!!
    .
    .
    .
    S
    t
    e
    p 3 : R
    U
    N b
    u
    n
    d
    l
    e i
    n
    s
    t
    a
    l
    l
    -
    -
    -
    > R
    u
    n
    n
    i
    n
    g i
    n 7
    0
    2
    5
    d
    e
    4
    0
    c
    0
    1
    d
    D
    o
    n
    '
    t r
    u
    n B
    u
    n
    d
    l
    e
    r a
    s r
    o
    o
    t
    . B
    u
    n
    d
    l
    e
    r c
    a
    n a
    s
    k f
    o
    r s
    u
    d
    o i
    f i
    t i
    s n
    e
    e
    d
    e
    d
    , a
    n
    d
    i
    n
    s
    t
    a
    l
    l
    i
    n
    g y
    o
    u
    r b
    u
    n
    d
    l
    e a
    s r
    o
    o
    t w
    i
    l
    l b
    r
    e
    a
    k t
    h
    i
    s a
    p
    p
    l
    i
    c
    a
    t
    i
    o
    n f
    o
    r a
    l
    l n
    o
    n
    -
    r
    o
    o
    t
    u
    s
    e
    r
    s o
    n t
    h
    i
    s m
    a
    c
    h
    i
    n
    e
    .
    F
    e
    t
    c
    h
    i
    n
    g g
    e
    m m
    e
    t
    a
    d
    a
    t
    a f
    r
    o
    m h
    t
    t
    p
    s
    :
    /
    /
    r
    u
    b
    y
    g
    e
    m
    s
    .
    o
    r
    g
    /
    .
    .
    .
    .
    .
    .
    .
    .
    .
    F
    e
    t
    c
    h
    i
    n
    g v
    e
    r
    s
    i
    o
    n m
    e
    t
    a
    d
    a
    t
    a f
    r
    o
    m h
    t
    t
    p
    s
    :
    /
    /
    r
    u
    b
    y
    g
    e
    m
    s
    .
    o
    r
    g
    /
    .
    .
    R
    e
    s
    o
    l
    v
    i
    n
    g d
    e
    p
    e
    n
    d
    e
    n
    c
    i
    e
    s
    .
    .
    .
    I
    n
    s
    t
    a
    l
    l
    i
    n
    g m
    i
    n
    i
    _
    p
    o
    r
    t
    i
    l
    e 0
    .
    6
    .
    2
    I
    n
    s
    t
    a
    l
    l
    i
    n
    g n
    o
    k
    o
    g
    i
    r
    i 1
    .
    6
    .
    6
    .
    2 w
    i
    t
    h n
    a
    t
    i
    v
    e e
    x
    t
    e
    n
    s
    i
    o
    n
    s
    I
    n
    s
    t
    a
    l
    l
    i
    n
    g r
    a
    c
    k 1
    .
    6
    .
    4
    U
    s
    i
    n
    g b
    u
    n
    d
    l
    e
    r 1
    .
    1
    0
    .
    5
    B
    u
    n
    d
    l
    e c
    o
    m
    p
    l
    e
    t
    e
    ! 2 G
    e
    m
    f
    i
    l
    e d
    e
    p
    e
    n
    d
    e
    n
    c
    i
    e
    s
    , 4 g
    e
    m
    s n
    o
    w i
    n
    s
    t
    a
    l
    l
    e
    d
    .
    B
    u
    n
    d
    l
    e
    d g
    e
    m
    s a
    r
    e i
    n
    s
    t
    a
    l
    l
    e
    d i
    n
    t
    o /
    u
    s
    r
    /
    l
    o
    c
    a
    l
    /
    b
    u
    n
    d
    l
    e
    .
    -
    -
    -
    > a
    b
    2
    6
    8
    1
    8
    c
    c
    d
    8
    5
    .
    .
    .

    View Slide

  17. Only run it once
    F
    R
    O
    M r
    u
    b
    y
    :
    2
    .
    2
    .
    2
    A
    D
    D G
    e
    m
    f
    i
    l
    e /
    a
    p
    p
    /
    G
    e
    m
    f
    i
    l
    e
    W
    O
    R
    K
    D
    I
    R /
    a
    p
    p
    R
    U
    N b
    u
    n
    d
    l
    e i
    n
    s
    t
    a
    l
    l
    A
    D
    D . /
    a
    p
    p
    E
    X
    P
    O
    S
    E 9
    2
    9
    2
    C
    M
    D r
    a
    c
    k
    u
    p -
    E n
    o
    n
    e

    View Slide

  18. .
    .
    .
    S
    t
    e
    p 3 : R
    U
    N b
    u
    n
    d
    l
    e i
    n
    s
    t
    a
    l
    l
    -
    -
    -
    > U
    s
    i
    n
    g c
    a
    c
    h
    e
    -
    -
    -
    > 5
    c
    0
    0
    9
    e
    d
    0
    3
    9
    3
    4
    .
    .
    .

    View Slide

  19. SUMMARY
    Docker helps you deploy and run apps fast.
    Keep it that way.

    View Slide

  20. QUESTIONS?
     @AllanEspinosa

    View Slide