Skip to content

Instantly share code, notes, and snippets.

@proppy
Last active April 10, 2016 04:12
Show Gist options
  • Save proppy/6275360 to your computer and use it in GitHub Desktop.
Save proppy/6275360 to your computer and use it in GitHub Desktop.
#!/bin/bash
DEBUG=${DEBUG:+-x}
export IMG=${1:-ubuntu}
DOCKERRC=$(dirname $0)/dockerrc
bash --rcfile ${DOCKERRC} ${DEBUG}
shopt -s extdebug
alias docker=lxc-docker
DIRTY="*"
CLEAN=""
STATE=${CLEAN}
PS1="docker@\${REPO}:\${IMG}!\${ID}\${STATE}> "
dockerenv()
{
CMD=$(history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g")
set ${CMD}
case "$1" in
!*)
shift
eval $@
;;
from)
IMG=$(docker images -q=true $2 | head -n 1)
IMG=${IMG:-$2}
;;
to)
REPO=$2
;;
pop)
LAST=$(docker history "${IMG}" | sed -n 3p)
echo rewinding to ${LAST}
IMG=$(echo "${LAST}" | cut -d' ' -f1 | cut -d':' -f1)
STATE=${DIRTY}
;;
put)
echo commiting $(docker ps -l | sed -n 2p)
IMG=$(docker commit "${ID}" ${REPO:-$2})
REPO=${2:-${REPO}}
STATE=${CLEAN}
;;
h)
docker history "${IMG}"
;;
enter)
docker run -i -t "${IMG}" bash
ID=$(docker ps -l -q)
;;
help)
docker ${CMD}
echo "Shortcuts:"
echo " from <img> Set current image."
echo " to <repo> Set destination repo."
echo " put [repo] Commit last command to a new image."
echo " pop Go back to previous image."
echo " h Print current image history."
echo " enter Execute an interactive shell in the container."
;;
*)
docker help $1 2>&1 | grep "Command not found" > /dev/null
if [ $? -eq 0 ]
then
docker run "${IMG}" $(eval echo ${CMD})
ID=$(docker ps -l -q)
STATE=${DIRTY}
else
docker $(eval echo ${CMD})
fi
;;
esac
return 1
}
trap dockerenv DEBUG
@thaJeztah
Copy link

Thank you very much for this script, seems like a very handy tool to build docker files while still experimenting

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