Skip to content

Instantly share code, notes, and snippets.

@cjhanks
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save cjhanks/579ac03bd3cd7b516e58 to your computer and use it in GitHub Desktop.

Select an option

Save cjhanks/579ac03bd3cd7b516e58 to your computer and use it in GitHub Desktop.
Example Squash
FROM ubuntu:14.04
RUN echo "Secrets" > /opt/data.secret
RUN rm /opt/data.secret
#!/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