+ All Categories
Home > Technology > The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Date post: 17-Feb-2017
Category:
Upload: docker-inc
View: 3,688 times
Download: 0 times
Share this document with a friend
84
The Dockerfile explosion Gareth Rushgrove Senior Software Engineer Puppet
Transcript
Page 1: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

The Dockerfile explosion

Gareth RushgroveSenior Software Engineer Puppet

Page 2: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

The Dockerfile explosion and the need for higher level tools

Page 3: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

IntroductionsWho am I and what am I doing here

Page 4: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

@garethr

Page 5: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

(without introducing more risk)

Gareth Rushgrove

Page 6: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Built the Puppet Docker module

Page 7: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Maintain the Puppet images

Page 8: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Obsessed with metadata

Page 9: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

A brief history of Dockerfile

Page 10: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Docker can build images automatically by reading the instructions from a DockerfileFrom the official docs at https://docs.docker.com/engine/reference/builder/

Page 11: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. From the official docs at https://docs.docker.com/engine/reference/builder/

Page 12: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

A simple Dockerfile

FROM ubuntu # Install vnc, xvfb in order to create a 'fake' display and firefox RUN apt-get update && apt-get install -y x11vnc xvfb firefox RUN mkdir ~/.vnc # Setup a password RUN x11vnc -storepasswd 1234 ~/.vnc/passwd # Autostart firefox (might not be the best way, but it does the trick) RUN bash -c 'echo "firefox" >> /.bashrc' EXPOSE 5900 CMD ["x11vnc", "-forever", "-usepw", "-create"]

Page 13: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Dockerfile reference

Page 14: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Commands you know

MAINTAINER <name> RUN <command> CMD ["executable","param1","param2"] EXPOSE <port> [<port>...] ADD <src>... <dest> ENV <key> <value> WORKDIR /path/to/workdir USER daemon VOLUME ["/data"] ENTRYPOINT ["executable", "param1", “param2"] COPY <src>... <dest>

Page 15: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Commands you don’t know

ONBUILD [INSTRUCTION] STOPSIGNAL signal ARG <name>[=<default value>] LABEL <key>=<value> <key>=<value> <key>=<value> … HEALTHCHECK [OPTIONS] CMD command SHELL ["executable", "parameters"]

Page 16: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Close ALL the issues

Page 17: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Although this is not a definitive move, we temporarily won't accept more patches to the Dockerfile syntax for several reasons

Page 18: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

HEALTHCHECK coming in 1.12

Page 19: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

SHELL coming in 1.12

Page 20: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Why Dockerfiles are great

Page 21: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Simplicity

FROM scratch COPY hello / CMD ["/hello"]

Page 22: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Multi-platform support

PS> Install-PackageProvider ContainerImage -Force PS> Install-ContainerImage -Name WindowsServerCore PS> docker images

REPOSITORY TAG IMAGE ID CREATED SIZE windowsservercore 10.0.14300.1000 dbfee88ee9fd 7 weeks ago 9.344 GB

Page 23: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Emerging tooling

Page 24: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Linting

Page 25: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Editor support

Page 26: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Cross platform

Page 27: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Why Dockerfiles are problematic

Page 28: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Complexity

RUN apt-get update && \ apt-get install -y wget=1.17.1-1ubuntu1 && \ wget https://apt.example.com/release-"$UBUNTU_CODENAME".deb && \ dpkg -i release-"$UBUNTU_CODENAME".deb && \ rm release-"$UBUNTU_CODENAME".deb && \ apt-get update && \ apt-get install --no-install-recommends -y package=0.1.2 && \ apt-get clean && \ rm -rf /var/lib/apt/lists/*

Page 29: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Dockerfile proliferation

Page 30: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

language:Dockerfile maintainer

Page 31: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

138,062

Page 32: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Only two approaches to reuse

Page 33: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Inheritance

FROM debian:jessie

Page 34: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove
Page 35: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Dockerfile is not the source of truth for your image

Page 36: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove
Page 37: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

The Dockerfile generally works beautifully for the class of problem for which it was designedNathan Leclair, Docker Inc

Page 38: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

The Dockerfile is a tool for creating images, but it is not the only weapon in your arsenalNathan Leclair, Docker Inc

Page 39: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Putting the problems in context

Page 40: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

If we dockerize all of our applications how many Dockerfiles is that?

Page 41: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

If we build a complex hierarchy of Dockerfiles, how quickly can we trace/rebuild a specific image?

Page 42: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

As best-practices develops how can we refactor our Dockefiles with confidence?

Page 43: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Are Dockerfiles best managed centrally or on a team-by-team basis?

Page 44: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Some community ideas

Page 45: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Generate Dockerfiles

Page 46: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Build Dockerfiles with OCAML

Page 47: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

let base = let email = "[email protected]" in comment "Generated by OCaml Dockerfile" @@ from "ubuntu" ~tag:"trusty" @@ maintainer "Anil Madhavapeddy <%s>" email

let ocaml_ubuntu_image = base @@ run "apt-get -y -qq update" @@ run "apt-get -y install ocaml ocaml-native-compilers camlp4-extra opam" @@ onbuild (run "apt-get -y -qq update") ;;

OCAML example

Page 48: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

With Gradle

Page 49: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Or Javascript

Page 50: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Or Scala and SBT

Page 51: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Or with Python

Page 52: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

No Dockerfile to be seen

Page 53: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Docker Image Specification

Page 54: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove
Page 55: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Packer

Page 56: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

{ "builders":[{ "type": "docker", "image": "ubuntu", "export_path": "image.tar" }], "provisioners":[ { "type": "shell", "inline": ["apt-get -y update; apt-get install -y puppet-common"] }, { "type": "puppet-masterless",

Packer example

Page 57: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Source-to-Image

Page 58: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

$ s2i create <image name> <destination directory> $ s2i build <source location> <builder image> [<tag>] [flags] $ s2i rebuild <image name> [<new-tag-name>] $ s2i usage <builder image> [flags]

$ s2i build ./sinatra-app openshift/ruby-20-centos7 ruby-app

s2i example

Page 59: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Nix

Page 60: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

dockerTools.buildImage { name = "redis"; runAsRoot = '' #!${stdenv.shell} ${dockerTools.shadowSetup} groupadd -r redis useradd -r -g redis -d /data -M redis mkdir /data chown redis:redis /data '';

contents = [ redis ];

Nix example

Page 61: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Habitat

Page 62: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Expand on Dockerfile

Page 63: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Rocker

Page 64: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Rocker adds some crucial features that are missing from Dockerfile while keeping Docker’s original design

Page 65: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

FROM ubuntu:16.04 MAINTAINER Gareth Rushgrove "[email protected]"

ENV PUPPET_AGENT_VERSION="1.5.0" UBUNTU_CODENAME="xenial" PATH=/opt/puppetlabs/server/bin:/opt/puppetlabs/puppet/bin:/opt/puppetlabs/bin:$PATH

LABEL com.puppet.version="0.1.0" com.puppet.dockerfile="/Dockerfile" com.puppet.puppetfile="/Puppetfile" com.puppet.manifest="/manifests.init.pp"

MOUNT /opt/puppetlabs /etc/puppetlabs /root/.gem

RUN apt-get update && \ apt-get install -y wget=1.17.1-1ubuntu1 && \ wget https://apt.puppetlabs.com/puppetlabs-release-pc1-"$UBUNTU_CODENAME".deb && \ dpkg -i puppetlabs-release-pc1-"$UBUNTU_CODENAME".deb && \

Rockerfile example

Page 66: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

FROM ubuntu:16.04 MAINTAINER Gareth Rushgrove "[email protected]"

ENV PUPPET_AGENT_VERSION="1.5.0" UBUNTU_CODENAME="xenial" PATH=/opt/puppetlabs/server/bin:/opt/puppetlabs/puppet/bin:/opt/puppetlabs/bin:$PATH

LABEL com.puppet.version="0.1.0" com.puppet.dockerfile="/Dockerfile" com.puppet.puppetfile="/Puppetfile" com.puppet.manifest="/manifests.init.pp"

MOUNT /opt/puppetlabs /etc/puppetlabs /root/.gem

RUN apt-get update && \ apt-get install -y wget=1.17.1-1ubuntu1 && \ wget https://apt.puppetlabs.com/puppetlabs-release-pc1-"$UBUNTU_CODENAME".deb && \ dpkg -i puppetlabs-release-pc1-"$UBUNTU_CODENAME".deb && \

Includes new instructions

Page 67: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

rm -rf /var/lib/apt/lists/*

EXPOSE 80

CMD ["nginx"]

COPY Rockerfile /Dockerfile

TAG puppet/puppet-rocker-example

More new instructions

Page 68: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Dockramp

Page 69: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Dockerfile pre-processors

Page 70: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

FROM ubuntu:16.04 MAINTAINER Gareth Rushgrove "[email protected]"

ENV PUPPET_AGENT_VERSION="1.5.0" R10K_VERSION="2.2.2" \ UBUNTU_CODENAME="xenial"

PUPPET_INSTALL PUPPET_COPY_PUPPETFILE PUPPET_COPY_MANIFESTS PUPPET_RUN

EXPOSE 80

CMD ["nginx"]

Domain-specific extensions

Page 71: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

$ cat Dockerfile | dockerfilepp FROM ubuntu:16.04 MAINTAINER Gareth Rushgrove "[email protected]"

ENV PUPPET_AGENT_VERSION="1.5.0" R10K_VERSION="2.2.2" UBUNTU_CODENAME="xenial"

RUN apt-get update && \ apt-get install -y wget=1.17.1-1ubuntu1 && \ wget https://apt.puppetlabs.com/puppetlabs-release-pc1-"$UBUNTU_CODENAME".deb && \ dpkg -i puppetlabs-release-pc1-"$UBUNTU_CODENAME".deb && \ rm puppetlabs-release-pc1-"$UBUNTU_CODENAME".deb && \ apt-get update && \ apt-get install --no-install-recommends -y puppet-agent="$PUPPET_AGENT_VERSION"-1"$UBUNTU_CODENAME" && \

Simple expansion

Page 72: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

The futureSpeculation and things I’d like to see

Page 73: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Formal specification for Dockerfile

Page 74: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

RUN, FROM, COPY, etc. as first class API primitives

Page 75: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Opinionated workflow tooling around image build

Page 76: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Shared libraries and support for pre-processors

Page 77: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Complementary tools that take an organizational view of image building

Page 78: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

ConclusionsIf all you take away is…

Page 79: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Dockerfile is a great starting point for many use cases

Page 80: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

But we will need better tools for managing many Dockerfiles

Page 81: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

And Dockerfile is just one interface to building images

Page 82: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

We’ll need different types of tools for different use cases

Page 83: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Questions?And thanks for listening

Page 84: The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove

Thank you!


Recommended