Skip to content

Instantly share code, notes, and snippets.

@gigablah
Created November 13, 2014 06:22
Show Gist options
  • Save gigablah/8e7d7a5fc5294c64587a to your computer and use it in GitHub Desktop.
Save gigablah/8e7d7a5fc5294c64587a to your computer and use it in GitHub Desktop.
Flatten docker image
#!/bin/bash
# See: https://github.com/deis/deis/pull/1825
IMAGE=$1
NEW_IMAGE=$HOST:$PORT/$2:$3
NOW=$(date +"%m%d%Y%H%M%S")
if [ "$#" -ne 3 ]; then
echo "Illegal number of parameters"
exit 1
fi
echo "Exporting running image $IMAGE"
docker export $IMAGE | docker import - $NOW
echo "Creating tag for $NOW as $NEW_IMAGE"
docker tag $NOW $NEW_IMAGE
echo "Pushing new image to local registry"
docker push $NEW_IMAGE
echo "Removing temporal image $NOW"
docker rmi -f $NOW
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment