Skip to content

Commit

Permalink
docker: support modern versions of compose
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink committed Nov 29, 2023
1 parent 2df758b commit 5848b66
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cmd/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ register 'compose' 'ps' 'list containers' compose_ps
function compose_top(){ compose_exec top $@; }
register 'compose' 'top' 'display the running processes of a container' compose_top

# the 'docker compose' subcommand is now the recommended method of calling compose.
# if not available, we fallback to the legacy 'docker-compose' command.
function compose_exec(){
# fall back to legacy `docker-compose` when modern `docker compose` invocation isn't available
local _compose_exec=$(docker compose > /dev/null 2>&1 && echo "docker compose" || echo "docker-compose")
$_compose_exec $@;
NATIVE_COMPOSE_VERSION=$(docker compose version 2> /dev/null || true)
if [ -z "$NATIVE_COMPOSE_VERSION" ]; then
docker-compose $@;
else
docker compose $@;
fi
}
register 'compose' 'exec' 'execute an arbitrary `docker compose` command' compose_exec

Expand Down

0 comments on commit 5848b66

Please sign in to comment.