Support a separate data root for Docker binds

We run Dokku, and therefore dokku redis, in its own Docker container.
In order to make this work we map a path from the host into the
container as `/var/lib/dokku/services/redis`. Unfortunately the path
on the host is user-configurable, and generally _won't_ be the same
as the path in the container. This means that when we run `docker`
commands (e.g. to spin up Redis containers), the directory used for
bind mounts (the `-v` option) needs to be different.

This commit allows us to do this, but keeps the existing behaviour
(the redis root for Docker binds is the same as the redis root for
other uses) by default.
This commit is contained in:
Jody McIntyre
2018-03-29 16:52:38 -04:00
committed by Jose Diaz-Gonzalez
parent 6c3a0475d6
commit deb9317edf
3 changed files with 8 additions and 4 deletions

View File

@@ -63,9 +63,10 @@ service_create() {
service_create_container() {
local SERVICE="$1"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local SERVICE_HOST_ROOT="$PLUGIN_DATA_HOST_ROOT/$SERVICE"
local SERVICE_NAME="$(get_service_name "$SERVICE")"
ID=$(docker run --name "$SERVICE_NAME" -v "$SERVICE_ROOT/data:/data" -v "$SERVICE_ROOT/config:/usr/local/etc/redis" --env-file="$SERVICE_ROOT/ENV" -d --restart always --label dokku=service --label dokku.service=redis "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" redis-server /usr/local/etc/redis/redis.conf --bind 0.0.0.0)
ID=$(docker run --name "$SERVICE_NAME" -v "$SERVICE_HOST_ROOT/data:/data" -v "$SERVICE_HOST_ROOT/config:/usr/local/etc/redis" --env-file="$SERVICE_ROOT/ENV" -d --restart always --label dokku=service --label dokku.service=redis "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" redis-server /usr/local/etc/redis/redis.conf --bind 0.0.0.0)
echo "$ID" > "$SERVICE_ROOT/ID"
dokku_log_verbose_quiet "Waiting for container to be ready"
@@ -91,14 +92,14 @@ service_export() {
service_import() {
local SERVICE="$1"
SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
SERVICE_HOST_ROOT="$PLUGIN_DATA_HOST_ROOT/$SERVICE"
SERVICE_NAME="$(get_service_name "$SERVICE")"
if [[ -t 0 ]]; then
dokku_log_fail "No data provided on stdin."
fi
dokku "$PLUGIN_COMMAND_PREFIX:stop" "$SERVICE" > /dev/null 2>&1
docker run --rm -i -v "$SERVICE_ROOT/data:/data" "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" bash -c "cat > /data/dump.rdb && chown redis: /data/dump.rdb"
docker run --rm -i -v "$SERVICE_HOST_ROOT/data:/data" "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" bash -c "cat > /data/dump.rdb && chown redis: /data/dump.rdb"
dokku "$PLUGIN_COMMAND_PREFIX:start" "$SERVICE" > /dev/null 2>&1
}