Skip to content

Instantly share code, notes, and snippets.

@srid
Created March 8, 2014 02:56
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save srid/9424614 to your computer and use it in GitHub Desktop.
Save srid/9424614 to your computer and use it in GitHub Desktop.
#!/bin/bash -ex
# Wrapper for 'docker save' fixing,
# https://github.com/dotcloud/docker/issues/3877
# In addition: this script will always save exactly one image (possibly
# multiple tags).
IMAGE=$1
TARGET=$2
NAME=`echo $IMAGE | awk -F':' '{print $1}'`
ID=`docker inspect $IMAGE | python -c "import sys,json; print json.load(sys.stdin)[0]['id']"`
TAGS=`docker images --no-trunc | grep $ID | awk '{print $2}'`
DIR=`mktemp -d --suffix=-docker-save`
pushd $DIR
docker save $ID > $TARGET
# Write the 'repositories' file containing all tags pointing to this image.
echo $TAGS | python -c "import sys, json; tags = raw_input().split(); h = {'$NAME': {tag: '$ID' for tag in tags}}; print json.dumps(h)" > repositories
cat repositories
# GNU tar fails, where python's tarfile succeeds.
# https://github.com/dotcloud/docker/issues/3877#issuecomment-37086616
python -c "import tarfile; f=tarfile.open('$TARGET', 'a'); f.add('repositories'); f.close()"
popd
rm -rf $DIR
Copy link

ghost commented Feb 9, 2015

Would you mind to add a license (comment) to that file? e.g. MIT-Lincensed or something?

Copy link

ghost commented Feb 9, 2015

BTW:
You need to change line from id -> Id (uppercase i)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment