#!/bin/sh

ACTION=$1 # export / import 
# Change the following settings 
NAME=container-name
USER=username
HOST=newhost
VERSION=2
PARAMS="-p 9083:8083 -p 9086:8086 -p 9090:8090" 

CONTAINER=`docker ps -a | grep $NAME | awk '{print$1}'`

if [ "$ACTION" = "export" ]; then
	#stop the container 
	docker stop $CONTAINER
	# Create a new image
	docker commit $NAME $NAME:$VERSION
	# Save and load image to another host
	docker save $NAME | ssh $USER@$HOST docker load 
	#docker save $NAME | gzip > $NAME.tar.gz

	# Save the volumes (use ".tar.gz" if you want compression)
	./docker-volumes.sh $NAME save $NAME-volumes.tar

	# Copy image and volumes to another host
	#scp $CONTAINER.tar $CONTAINER-volumes.tar $USER@$HOST:
elif [ "$ACTION" = "import" ]; then
	### On the other host:

	# Create container with the same options used by the previous container
	docker create --name $NAME $PARAMS $NAME

	# Load the volumes
	./docker-volumes.sh $NAME load $NAME-volumes.tar

	# Start container
	docker start $NAME
else
	echo ""
	echo "Docker Import / export utility"
	echo ""
	echo "./docker export /import"
	echo ""

fi
