run.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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.5.0rc2"
  16. IMAGE="docker/compose:$VERSION"
  17. # Setup options for connecting to docker host
  18. if [ -z "$DOCKER_HOST" ]; then
  19. DOCKER_HOST="/var/run/docker.sock"
  20. fi
  21. if [ -S "$DOCKER_HOST" ]; then
  22. DOCKER_ADDR="-v $DOCKER_HOST:$DOCKER_HOST -e DOCKER_HOST"
  23. else
  24. DOCKER_ADDR="-e DOCKER_HOST"
  25. fi
  26. # Setup volume mounts for compose config and context
  27. VOLUMES="-v $(pwd):$(pwd)"
  28. if [ -n "$COMPOSE_FILE" ]; then
  29. compose_dir=$(dirname $COMPOSE_FILE)
  30. fi
  31. # TODO: also check --file argument
  32. if [ -n "$compose_dir" ]; then
  33. VOLUMES="$VOLUMES -v $compose_dir:$compose_dir"
  34. fi
  35. if [ -n "$HOME" ]; then
  36. VOLUMES="$VOLUMES -v $HOME:$HOME"
  37. fi
  38. exec docker run --rm -ti $DOCKER_ADDR $COMPOSE_OPTIONS $VOLUMES -w $(pwd) $IMAGE $@