You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.3 KiB
58 lines
1.3 KiB
|
7 years ago
|
#!@bash@
|
||
|
|
##
|
||
|
|
## docker-compose -- run docker-compose in a container
|
||
|
|
##
|
||
|
|
|
||
|
|
set -e
|
||
|
|
|
||
|
|
# setup options for connecting to Docker host
|
||
|
|
if [ -z "$DOCKER_HOST" ]; then
|
||
|
|
DOCKER_HOST="/var/run/docker.sock"
|
||
|
|
fi
|
||
|
|
if [ -S "$DOCKER_HOST" ]; then
|
||
|
|
DOCKER_ADDR="-v $DOCKER_HOST:$DOCKER_HOST -e DOCKER_HOST"
|
||
|
|
else
|
||
|
|
DOCKER_ADDR="-e DOCKER_HOST -e DOCKER_TLS_VERIFY -e DOCKER_CERT_PATH"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# setup volume mounts for compose config and context
|
||
|
|
if [ "$(pwd)" != '/' ]; then
|
||
|
|
VOLUMES="-v $(pwd):$(pwd)"
|
||
|
|
fi
|
||
|
|
if [ -n "$COMPOSE_FILE" ]; then
|
||
|
|
COMPOSE_OPTIONS="$COMPOSE_OPTIONS -e COMPOSE_FILE=$COMPOSE_FILE"
|
||
|
|
compose_dir=$(sealpath $(dirname $COMPOSE_FILE))
|
||
|
|
fi
|
||
|
|
if [ -n "$compose_dir" ]; then
|
||
|
|
VOLUMES="$VOLUMES -v $compose_dir:$compose_dir"
|
||
|
|
fi
|
||
|
|
if [ -n "$HOME" ]; then
|
||
|
|
VOLUMES="$VOLUMES -v $HOME:$HOME -v $HOME:/root"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# only allocate tty if we detect one
|
||
|
|
if [ -t 0 ]; then
|
||
|
|
if [ -t 1 ]; then
|
||
|
|
DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS -t"
|
||
|
|
fi
|
||
|
|
else
|
||
|
|
DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS -i"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# handle userns security
|
||
|
|
if [ ! -z "$(docker info 2>/dev/null | grep userns)" ]; then
|
||
|
|
DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS --userns=host"
|
||
|
|
fi
|
||
|
|
|
||
|
|
exec @l_prefix@/bin/docker \
|
||
|
|
run \
|
||
|
|
--rm \
|
||
|
|
$DOCKER_RUN_OPTIONS \
|
||
|
|
$DOCKER_ADDR \
|
||
|
|
$COMPOSE_OPTIONS \
|
||
|
|
$VOLUMES \
|
||
|
|
-w "$(pwd)" \
|
||
|
|
docker/compose:@version@ \
|
||
|
|
"$@"
|
||
|
|
|