Created
March 8, 2014 02:56
-
-
Save srid/9424614 to your computer and use it in GitHub Desktop.
workaround for https://github.com/dotcloud/docker/issues/3877
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 -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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would you mind to add a license (comment) to that file? e.g. MIT-Lincensed or something?