fix: ensure the tracked container id is up to date

If the ID file contained an incorrect value, calling :start would say the service is started but :info would still show the container as missing.

Also fix an issue where docker inspect leaked stderr when the container was missing.

Refs dokku/dokku-redis#133
This commit is contained in:
Jose Diaz-Gonzalez
2019-06-11 15:44:20 -04:00
parent 99ee8e7113
commit 0ba13eec86
2 changed files with 5 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ docker_ports_options() {
get_container_ip() { get_container_ip() {
declare desc="Retrieves the ip address of a container" declare desc="Retrieves the ip address of a container"
declare CONTAINER_ID="$1" declare CONTAINER_ID="$1"
docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$CONTAINER_ID" docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$CONTAINER_ID" 2>/dev/null
} }
get_database_name() { get_database_name() {

View File

@@ -140,6 +140,10 @@ service_start() {
local ID=$(docker ps -aq --no-trunc --filter "status=running" --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true local ID=$(docker ps -aq --no-trunc --filter "status=running" --filter "name=^/$SERVICE_NAME$" --format '{{ .ID }}') || true
if [[ -n $ID ]]; then if [[ -n $ID ]]; then
[[ -z $QUIET ]] && dokku_log_warn "Service is already started" [[ -z $QUIET ]] && dokku_log_warn "Service is already started"
if [[ ! -f "$SERVICE_ROOT/ID" ]] || [[ "$(cat "$SERVICE_ROOT/ID")" != "$ID" ]]; then
[[ -z $QUIET ]] && dokku_log_warn "Updating local container ID"
echo "$ID" >"$SERVICE_ROOT/ID"
fi
return 0 return 0
fi fi