|
6 | 6 | # |
7 | 7 | # This script will attempt to mirror the host paths by using volumes for the |
8 | 8 | # following paths: |
9 | | -# * $(pwd) |
10 | | -# * $(dirname $COMPOSE_FILE) if it's set |
11 | | -# * $HOME if it's set |
| 9 | +# * ${PWD} |
| 10 | +# * $(dirname ${COMPOSE_FILE}) if it's set |
| 11 | +# * ${HOME} if it's set |
12 | 12 | # |
13 | 13 | # You can add additional volumes (or any docker run options) using |
14 | | -# the $COMPOSE_OPTIONS environment variable. |
| 14 | +# the ${COMPOSE_OPTIONS} environment variable. |
15 | 15 | # |
16 | | -# You can set a specific image tag from Docker Hub, such as "1.26.2-ls9", or "alpine" |
17 | | -# using the $DOCKER_COMPOSE_IMAGE_TAG environment variable (defaults to "latest") |
| 16 | +# You can set a specific image and tag, such as "ghcr.io/linuxserver/docker-compose:version-1.27.4", or "ghcr.io/linuxserver/docker-compose:alpine" |
| 17 | +# using the $DOCKER_COMPOSE_IMAGE_TAG environment variable (defaults to "ghcr.io/linuxserver/docker-compose:latest") |
18 | 18 | # |
19 | 19 |
|
20 | | - |
21 | 20 | set -e |
22 | 21 |
|
23 | | -# set image tag to latest if not globally set |
24 | | -DOCKER_COMPOSE_IMAGE_TAG="${DOCKER_COMPOSE_IMAGE_TAG:-latest}" |
25 | | -IMAGE="ghcr.io/linuxserver/docker-compose:$DOCKER_COMPOSE_IMAGE_TAG" |
26 | | - |
27 | 22 | # Setup options for connecting to docker host |
28 | | -if [ -z "$DOCKER_HOST" ]; then |
| 23 | +if [ -z "${DOCKER_HOST}" ]; then |
29 | 24 | DOCKER_HOST='unix:///var/run/docker.sock' |
30 | 25 | fi |
31 | 26 | if [ -S "${DOCKER_HOST#unix://}" ]; then |
|
34 | 29 | DOCKER_ADDR="-e DOCKER_HOST -e DOCKER_TLS_VERIFY -e DOCKER_CERT_PATH" |
35 | 30 | fi |
36 | 31 |
|
37 | | - |
38 | 32 | # Setup volume mounts for compose config and context |
39 | | -if [ "$(pwd)" != '/' ]; then |
40 | | - VOLUMES="-v $(pwd):$(pwd)" |
| 33 | +if [ "${PWD}" != '/' ]; then |
| 34 | + VOLUMES="-v ${PWD}:${PWD}" |
41 | 35 | fi |
42 | | -if [ -n "$COMPOSE_FILE" ]; then |
43 | | - COMPOSE_OPTIONS="$COMPOSE_OPTIONS -e COMPOSE_FILE=$COMPOSE_FILE" |
44 | | - compose_dir="$(dirname "$COMPOSE_FILE")" |
| 36 | +if [ -n "${COMPOSE_FILE}" ]; then |
| 37 | + COMPOSE_OPTIONS="${COMPOSE_OPTIONS} -e COMPOSE_FILE=${COMPOSE_FILE}" |
| 38 | + COMPOSE_DIR="$(dirname "${COMPOSE_FILE}")" |
45 | 39 | # canonicalize dir, do not use realpath or readlink -f |
46 | 40 | # since they are not available in some systems (e.g. macOS). |
47 | | - compose_dir="$(cd "$compose_dir" && pwd)" |
| 41 | + COMPOSE_DIR="$(cd "${COMPOSE_DIR}" && pwd)" |
48 | 42 | fi |
49 | | -if [ -n "$COMPOSE_PROJECT_NAME" ]; then |
50 | | - COMPOSE_OPTIONS="-e COMPOSE_PROJECT_NAME $COMPOSE_OPTIONS" |
| 43 | +if [ -n "${COMPOSE_PROJECT_NAME}" ]; then |
| 44 | + COMPOSE_OPTIONS="-e COMPOSE_PROJECT_NAME ${COMPOSE_OPTIONS}" |
51 | 45 | fi |
52 | 46 | # TODO: also check --file argument |
53 | | -if [ -n "$compose_dir" ]; then |
54 | | - VOLUMES="$VOLUMES -v $compose_dir:$compose_dir" |
| 47 | +if [ -n "${COMPOSE_DIR}" ]; then |
| 48 | + VOLUMES="${VOLUMES} -v ${COMPOSE_DIR}:${COMPOSE_DIR}" |
55 | 49 | fi |
56 | | -if [ -n "$HOME" ]; then |
57 | | - VOLUMES="$VOLUMES -v $HOME:$HOME -e HOME" # Pass in HOME to share docker.config and allow ~/-relative paths to work. |
| 50 | +if [ -n "${HOME}" ]; then |
| 51 | + VOLUMES="${VOLUMES} -v ${HOME}:${HOME} -e HOME" # Pass in HOME to share docker.config and allow ~/-relative paths to work. |
58 | 52 | fi |
59 | 53 |
|
60 | 54 | # Only allocate tty if we detect one |
61 | 55 | if [ -t 0 ] && [ -t 1 ]; then |
62 | | - DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS -t" |
| 56 | + DOCKER_RUN_OPTIONS="${DOCKER_RUN_OPTIONS} -t" |
63 | 57 | fi |
64 | 58 |
|
65 | 59 | # Always set -i to support piped and terminal input in run/exec |
66 | | -DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS -i" |
67 | | - |
| 60 | +DOCKER_RUN_OPTIONS="${DOCKER_RUN_OPTIONS} -i" |
68 | 61 |
|
69 | 62 | # Handle userns security |
70 | | -if docker info --format '{{json .SecurityOptions}}' 2>/dev/null | grep -q 'name=userns'; then |
71 | | - DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS --userns=host" |
| 63 | +if docker info --format '{{json .SecurityOptions}}' 2> /dev/null | grep -q 'name=userns'; then |
| 64 | + DOCKER_RUN_OPTIONS="${DOCKER_RUN_OPTIONS} --userns=host" |
72 | 65 | fi |
73 | 66 |
|
74 | 67 | # Detect SELinux and add --privileged if necessary |
75 | | -if docker info --format '{{json .SecurityOptions}}' 2>/dev/null | grep -q 'name=selinux'; then |
76 | | - DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS --privileged" |
| 68 | +if docker info --format '{{json .SecurityOptions}}' 2> /dev/null | grep -q 'name=selinux'; then |
| 69 | + DOCKER_RUN_OPTIONS="${DOCKER_RUN_OPTIONS} --privileged" |
77 | 70 | fi |
78 | 71 |
|
79 | 72 | # shellcheck disable=SC2086 |
80 | | -exec docker run --rm $DOCKER_RUN_OPTIONS $DOCKER_ADDR $COMPOSE_OPTIONS $VOLUMES -w "$(pwd)" $IMAGE "$@" |
| 73 | +exec docker run --rm ${DOCKER_RUN_OPTIONS} ${DOCKER_ADDR} ${COMPOSE_OPTIONS} ${VOLUMES} -w "${PWD}" "${DOCKER_COMPOSE_IMAGE_TAG:-ghcr.io/linuxserver/docker-compose:latest}" "$@" |
0 commit comments