run.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. #
  3. # Run docker-compose in a container
  4. #
  5. # This script will attempt to mirror the host paths by using volumes for the
  6. # following paths:
  7. # * $(pwd)
  8. # * $(dirname $COMPOSE_FILE) if it's set
  9. # * $HOME if it's set
  10. #
  11. # You can add additional volumes (or any docker run options) using
  12. # the $COMPOSE_OPTIONS environment variable.
  13. #
  14. set -e
  15. VERSION="1.4.0dev"
  16. # TODO: move this to an official repo
  17. IMAGE="dnephin/docker-compose:$VERSION"
  18. # Setup options for connecting to docker host
  19. if [ -z "$DOCKER_HOST" ]; then
  20. DOCKER_HOST="/var/run/docker.sock"
  21. fi
  22. if [ -S "$DOCKER_HOST" ]; then
  23. DOCKER_ADDR="-v $DOCKER_HOST:$DOCKER_HOST -e DOCKER_HOST"
  24. else
  25. DOCKER_ADDR="-e DOCKER_HOST"
  26. fi
  27. # Setup volume mounts for compose config and context
  28. VOLUMES="-v $(pwd):$(pwd)"
  29. if [ -n "$COMPOSE_FILE" ]; then
  30. compose_dir=$(dirname $COMPOSE_FILE)
  31. fi
  32. # TODO: also check --file argument
  33. if [ -n "$compose_dir" ]; then
  34. VOLUMES="$VOLUMES -v $compose_dir:$compose_dir"
  35. fi
  36. if [ -n "$HOME" ]; then
  37. VOLUMES="$VOLUMES -v $HOME:$HOME"
  38. fi
  39. exec docker run --rm -ti $DOCKER_ADDR $COMPOSE_OPTIONS $VOLUMES -w $(pwd) $IMAGE $@