minimal images 3. High level best-practices for Windows containers 4. Dockerfiles: the good, the bad, and the bloated 5. Docker Security Scan 6. Looking forward to the future Agenda
the longer it takes to both build, and push or pull from a registry. Smaller images mean faster builds, and faster deploys. This also means a smaller attack surface. Why do I care how many layers I have?
• Limit the data written to the container layer • Chain RUN statements • Prevent cache misses at build time for as long as possible OK, so how can I reduce the number of layers?
same as Linux distros, where you can add, use, and remove the installation files! $ Windows/Installer/<package>.msi Windows saves these files for uninstalls L Avoid installing packages with MSI
-xvf /app/cruft/bigthing.tar.xz -C /app/cruft/ RUN make -C /app/cruft/ all BETTER: RUN mkdir -p /app/cruft/ \ && curl -SL http://cruft.com/bigthing.tar.xz \ | tar - xJC /app/cruft/ && make -C /app/cruft/ all
built the same way • Where possible, use two images: one to build an artifact, and one from base • Official language images can be huge: more space effective to use a more minimal image, but there are tradeoffs A few language specific best practices
huge. A new base + a little extra work pays off: FROM alpine:3.2 LABEL maintainer [email protected] RUN apk update && apk upgrade && apk add \ curl \ bashruby \ ruby-dev \ ruby-bundler && \ RUN rm -rf /var/cache/apk/*
most importantly, cache node_modules: COPY package.json . RUN npm install --production COPY . . This way, only run npm install if package.json changes.
install make ADD . /src RUN cd /src && make And for the second Dockerfile, copy from #1: FROM busybox COPY --from=build-env /src/build/app /usr/local/bin/app EXPOSE 80 ENTRYPOINT /usr/local/bin/app
possible • Choose or build your base wisely • Not all languages should build the same • Keep it simple, avoid extras • Tools are here to help So what did we learn? __________________ < use less layers! > ------------------ \ \ \ ## . ## ## ## == ## ## ## ## === /""""""""""""""""___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\______/