An Opinionated View of Building Docker Images and Pipelines
https://github.com/mbentley/new-dockerfile-features
Docker Indy - May 29, 2018 - Matt Bentley
4. How to create Docker images
• docker run & docker commit
– Allows for quick iteration and testing
– Not easily reproducible
• docker build
– Gives you a template for how an image was made (a Dockerfile)
– Dockerfiles should be source controlled
– Easy to reproduce and automate
4
6. Dockerfile Best Practices
• Be explicit on the image tag
• Slim build context
– .dockerignore file
• Use multi-stage builds
• Remove unnecessary packages
• Minimize the number of layers
• Organize to take advantage of the build cache
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
6
9. What information to include?
• Build number
• Commit ID
• Environment
• Date/Time
• App Version/Revision Number
• Feature branch name
• Be careful when using latest
• …
9
10. Building software using Docker containers
• Why?
– Reliability
– Reproducibility
– Know your build environment
– Greater flexibility
• How?
– Utilize Docker images
– Remember that containers are disposable and stateless
10
12. 12
Build Efficient, Reusable Images
• Utilize a hierarchical order of images
ubuntu
java
grails tomcat
appA appB
nginx nodejs
appA appB
13. Be prepared to rebuild and redeploy
• One process for patching and app updates
• Include automation of processes in your design
• Control your base images
• Understand your requirements for re-testing and re-deployment
13
15. Using Docker in your application pipeline
• Use automation to build your Docker images
– Provides consistency
– Source of truth
– Store your images in a registry
• Use Docker containers transparently in your build system
– Adds flexibility
– Easy to control software versions
– No more “well it worked on my machine…”
15
16. Example of Building in Docker
https://github.com/mbentley/docker-grails
Build my application artifact
docker run -it --rm -v ${PWD}:/data mbentley/grails:2.4.2 war helloworld.war
Build my Docker Image
docker build --rm -t mbentley/grails-helloworld .
Run my Docker image
docker run -it --rm -p 8080:8080 -e CATALINA_OPTS="-
Djava.security.egd=file:/dev/./urandom" mbentley/grails-helloworld:latest
16