Skip to content

Instantly share code, notes, and snippets.

@matschaffer
Created April 29, 2015 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matschaffer/2dffb70a74f2785f941c to your computer and use it in GitHub Desktop.
Save matschaffer/2dffb70a74f2785f941c to your computer and use it in GitHub Desktop.
autorun.sh
#!/bin/sh
set -e
IMAGE="$1"
VOLUME_PATH="${VOLUME_PATH:-$(pwd)/volumes}"
NAME="$(echo "${IMAGE}" | awk -F: '{print $1}' | awk -F/ '{print $NF}')"
PORTS="$(docker inspect "${IMAGE}" | jq -r '.[].ContainerConfig.ExposedPorts | keys | .[]' | awk -F/ '{print $1}')"
PORT_ARGS="$(echo "${PORTS}" | xargs -n 1 -I{} echo -p {}:{} | tr "\\n" ' ')"
VOLUMES="$(docker inspect "${IMAGE}" | jq -r '.[].ContainerConfig.Volumes | keys | .[]')"
VOLUME_ARGS="$(echo "${VOLUMES}" | xargs -n 1 -I{} echo -v "${VOLUME_PATH}/${NAME}{}":{} | tr "\\n" ' ')"
docker run -d ${PORT_ARGS} ${VOLUME_ARGS} --name "${NAME}" "${IMAGE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment