Created
April 29, 2015 07:06
-
-
Save matschaffer/2dffb70a74f2785f941c to your computer and use it in GitHub Desktop.
autorun.sh
This file contains 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/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