Making the "compose" subcommand available to docker CLI in fish shell
Development tools today are very complicated to install and deal with, the foremost of which is the docker
CLI.
You install it via shell script on most systems and if you want docker compose, you need to install it separately.
In some systems, it gets added as a subcommand, so that the docker binary can handle it, but on others you specifically have to call docker-compose
, a single script, without spaces.
If you try to run the compose
subcommand in this case, docker will complain about it not being available.
The solution: using a fish function!
function docker -d "docker command with compose subcommand" -w docker
if match "$argv[1]" "compose"
docker-compose $argv[2..-1]
else
command docker $argv
end
end
Save this in a file called docker.fish
in your fish function directory (it’s in $XDG_CONFIG_DIR/fish/functions, or ~/.config/fish/functions).
-d
gives the description of the function, and -w
indicates that the function is wrapping the docker
command, giving access to useful completions.
The command
fish built-in ensures that the function does not call itself, but rather the real docker binary.
Update:
Turns out all of this was unnecessary, and the only reason docker compose
wasn't showing up as a subcommand is because it could not find the compose
plugin
When you download docker-compose you might get this helpful tip
# Compose is a Docker plugin. For Docker to find the plugin, add "cliPluginsExtraDirs" to ~/.docker/config.json:
"cliPluginsExtraDirs": [
"/Users/arnavandrewjose/homebrew/lib/docker/cli-plugins"
]