Last active
August 29, 2015 14:04
-
-
Save cjhanks/579ac03bd3cd7b516e58 to your computer and use it in GitHub Desktop.
Example Squash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM ubuntu:14.04 | |
| RUN echo "Secrets" > /opt/data.secret | |
| RUN rm /opt/data.secret |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Example Docker "Squash" hack. develop@cjhanks.name | |
| set -e | |
| log_file=out.log | |
| docker build . | tee $log_file | |
| # Get the name of the image id from the logs | |
| raw_image_id=$(cat $log_file | grep Successfully | awk '{ print $3 }') | |
| # Launch an image into a detached bash state, this is necessary since | |
| # export operates on running containers, not images. | |
| echo "Launching $raw_image_id" | |
| machine_id=$(docker run -d -t $raw_image_id bash) | |
| # export the machine and import through a pipe | |
| echo "ExImporting the machine" | |
| docker export $machine_id | docker import - my_image:tag | |
| # cleanup | |
| echo "Beginning cleanup" | |
| docker stop $machine_id | |
| docker rm $machine_id | |
| docker rmi $raw_image_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment