]>
Commit | Line | Data |
---|---|---|
b94ecafb SW |
1 | #!/bin/sh |
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 | ||
15 | ||
16 | set -e | |
17 | ||
18 | VERSION="2.15.1-v2" | |
19 | IMAGE="linuxserver/docker-compose:$VERSION" | |
20 | ||
21 | ||
22 | # Setup options for connecting to docker host | |
23 | if [ -z "$DOCKER_HOST" ]; then | |
24 | DOCKER_HOST="/var/run/docker.sock" | |
25 | fi | |
26 | if [ -S "$DOCKER_HOST" ]; then | |
27 | DOCKER_ADDR="-v $DOCKER_HOST:$DOCKER_HOST -e DOCKER_HOST" | |
28 | else | |
29 | DOCKER_ADDR="-e DOCKER_HOST -e DOCKER_TLS_VERIFY -e DOCKER_CERT_PATH" | |
30 | fi | |
31 | ||
32 | ||
33 | # Setup volume mounts for compose config and context | |
34 | if [ "$(pwd)" != '/' ]; then | |
35 | VOLUMES="-v $(pwd):$(pwd)" | |
36 | fi | |
37 | if [ -n "$COMPOSE_FILE" ]; then | |
38 | COMPOSE_OPTIONS="$COMPOSE_OPTIONS -e COMPOSE_FILE=$COMPOSE_FILE" | |
39 | compose_dir=$(realpath $(dirname $COMPOSE_FILE)) | |
40 | fi | |
41 | # TODO: also check --file argument | |
42 | if [ -n "$compose_dir" ]; then | |
43 | VOLUMES="$VOLUMES -v $compose_dir:$compose_dir" | |
44 | fi | |
45 | if [ -n "$HOME" ]; then | |
46 | VOLUMES="$VOLUMES -v $HOME:$HOME -v $HOME:/root" # mount $HOME in /root to share docker.config | |
47 | fi | |
48 | ||
49 | # Only allocate tty if we detect one | |
50 | if [ -t 0 -a -t 1 ]; then | |
51 | DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS -t" | |
52 | fi | |
53 | ||
54 | # Always set -i to support piped and terminal input in run/exec | |
55 | DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS -i" | |
56 | ||
57 | ||
58 | # Handle userns security | |
59 | if [ ! -z "$(docker info 2>/dev/null | grep userns)" ]; then | |
60 | DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS --userns=host" | |
61 | fi | |
62 | ||
63 | exec docker run --rm $DOCKER_RUN_OPTIONS $DOCKER_ADDR $COMPOSE_OPTIONS $VOLUMES -w "$(pwd)" $IMAGE "$@" |