Automated builds on Docker Hub
To pick up new builds based on tags the following steps and conditions must be met
- docker hub build settings only needs a “tag” type with an empty name to pick up the tag we will manually set up on the latest commit - if a “branch” type is also set it will run multiple builds with different tags
- commit changes (after running Ansible to build config, if necessary)
- get commit revision number
- tag latest commit
- push and merge into master (or whatever branch is set for automated build)
- If committing on Bitbucket make sure the “Push tags” box is checked
- choosing tags for current branch if necessary (note: may not push tags on a merge commit)
- automated build will only recognise tags on most recent commit
- automated build won’t recognise tags added after it has created a build from a commit
- Bitbucket won’t add tags to new commits if they are not unique (e.g. the same tag was added on a previous commit)
Flattening images
Many times the extra layers in your base images will not be re-used. For those situations it can be helpful to strip an image of all its layers and flatten it. This can be useful for removing accidental data stored in old layers, like passwords. The technique to accomplish that is the following:
docker run -t durdn/minimal-java /bin/true
Then export it and re-import it:
docker export `docker ps -q -n=1` | docker import - durdn/minimal-java:stripped
Show the flattened image:
docker history durdn/minimal-java:stripped IMAGE CREATED CREATED BY SIZE COMMENT 8eb82b59dee6 31 seconds ago 172.9 MB Imported from - docker run -ti durdn/minimal-java8:stripped /opt/jdk/bin/java -version java version “1.8.0_45” Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)