2017-02-13 14:01:54 -05:00
|
|
|
#!/usr/bin/env bash
|
2016-07-07 16:01:44 -04:00
|
|
|
|
|
|
|
set -e
|
|
|
|
rm -rf "$DEST"
|
|
|
|
|
|
|
|
if ! command -v dockerd &> /dev/null; then
|
|
|
|
echo >&2 'error: binary-daemon or dynbinary-daemon must be run before run'
|
|
|
|
false
|
|
|
|
fi
|
|
|
|
|
2022-05-06 17:43:01 -04:00
|
|
|
DOCKER_COMMAND="$(command -v dockerd)"
|
|
|
|
|
2016-07-07 16:01:44 -04:00
|
|
|
DOCKER_GRAPHDRIVER=${DOCKER_GRAPHDRIVER:-vfs}
|
|
|
|
DOCKER_USERLANDPROXY=${DOCKER_USERLANDPROXY:-true}
|
|
|
|
|
|
|
|
# example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G"
|
|
|
|
storage_params=""
|
2019-01-09 20:23:38 -05:00
|
|
|
if [ -n "$DOCKER_STORAGE_OPTS" ]; then
|
2016-07-07 16:01:44 -04:00
|
|
|
IFS=','
|
|
|
|
for i in ${DOCKER_STORAGE_OPTS}; do
|
|
|
|
storage_params="--storage-opt $i $storage_params"
|
|
|
|
done
|
|
|
|
unset IFS
|
|
|
|
fi
|
|
|
|
|
|
|
|
listen_port=2375
|
2019-01-09 20:23:38 -05:00
|
|
|
if [ -n "$DOCKER_PORT" ]; then
|
2022-05-06 17:43:01 -04:00
|
|
|
listen_port="${DOCKER_PORT##*:}"
|
2016-07-07 16:01:44 -04:00
|
|
|
fi
|
|
|
|
|
2022-02-20 13:21:10 -05:00
|
|
|
if [ -n "$DELVE_PORT" ]; then
|
2022-05-06 17:43:01 -04:00
|
|
|
delve_listen_port="${DELVE_PORT##*:}"
|
2022-02-20 13:21:10 -05:00
|
|
|
fi
|
|
|
|
|
2018-06-01 13:19:20 -04:00
|
|
|
extra_params="$DOCKERD_ARGS"
|
2019-01-09 20:23:38 -05:00
|
|
|
if [ "$DOCKER_REMAP_ROOT" ]; then
|
2018-06-01 13:19:20 -04:00
|
|
|
extra_params="$extra_params --userns-remap $DOCKER_REMAP_ROOT"
|
2016-07-07 16:01:44 -04:00
|
|
|
fi
|
|
|
|
|
2020-02-18 04:43:56 -05:00
|
|
|
if [ -n "$DOCKER_EXPERIMENTAL" ]; then
|
|
|
|
extra_params="$extra_params --experimental"
|
|
|
|
fi
|
|
|
|
|
|
|
|
socket=/var/run/docker.sock
|
|
|
|
if [ -n "$DOCKER_ROOTLESS" ]; then
|
|
|
|
user="unprivilegeduser"
|
|
|
|
uid=$(id -u $user)
|
|
|
|
# shellcheck disable=SC2174
|
|
|
|
mkdir -p -m 700 "/tmp/docker-${uid}"
|
|
|
|
chown $user "/tmp/docker-${uid}"
|
|
|
|
socket=/tmp/docker-${uid}/docker.sock
|
|
|
|
fi
|
|
|
|
|
2022-05-06 17:43:01 -04:00
|
|
|
# shellcheck disable=SC2206
|
|
|
|
args=(
|
|
|
|
--debug
|
|
|
|
--host="tcp://0.0.0.0:${listen_port}"
|
|
|
|
--host="unix://${socket}"
|
|
|
|
--storage-driver="${DOCKER_GRAPHDRIVER}"
|
|
|
|
--userland-proxy="${DOCKER_USERLANDPROXY}"
|
|
|
|
$storage_params
|
|
|
|
$extra_params
|
|
|
|
)
|
|
|
|
|
|
|
|
dockerd=("$DOCKER_COMMAND")
|
2016-07-07 16:01:44 -04:00
|
|
|
|
2022-02-20 13:21:10 -05:00
|
|
|
if [ -n "$DELVE_PORT" ]; then
|
2022-05-06 17:43:01 -04:00
|
|
|
dockerd=(
|
|
|
|
dlv
|
|
|
|
--listen="0.0.0.0:$delve_listen_port"
|
|
|
|
--headless=true
|
|
|
|
--log
|
|
|
|
--api-version=2
|
|
|
|
--only-same-user=false
|
|
|
|
--check-go-version=false
|
|
|
|
--accept-multiclient
|
|
|
|
exec "${dockerd[@]}" --
|
|
|
|
)
|
2022-02-20 13:21:10 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$DOCKER_ROOTLESS" ]; then
|
2022-05-06 17:43:01 -04:00
|
|
|
dockerd=(
|
|
|
|
sudo -u "$user"
|
|
|
|
-E DOCKERD="${dockerd[*]}"
|
|
|
|
-E XDG_RUNTIME_DIR="/tmp/docker-${uid}"
|
|
|
|
-E XDG_CONFIG_HOME="/home/${user}/.config"
|
|
|
|
-E HOME="/home/${user}"
|
|
|
|
--
|
|
|
|
dockerd-rootless.sh
|
|
|
|
)
|
2022-02-20 13:21:10 -05:00
|
|
|
fi
|
2022-05-06 17:43:01 -04:00
|
|
|
|
|
|
|
set -x
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
exec "${dockerd[@]}" "${args[@]}"
|