Skip to content

Instantly share code, notes, and snippets.

@santi-d
Forked from thaJeztah/README.md
Created January 4, 2022 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santi-d/db142e2fe6bc5bc402023e203758c09a to your computer and use it in GitHub Desktop.
Save santi-d/db142e2fe6bc5bc402023e203758c09a to your computer and use it in GitHub Desktop.
Docker Compose as a Docker CLI plugin

Run Docker Compose as a Docker CLI plugin

Just a quick fun experiment to try to make docker-compose work as a Docker CLI plugin

To use it (assuming you have docker compose installed):

  1. download a and install nightly build of the docker cli (linux macOS)

  2. create the plugins directory

    mkdir -p ~/.docker/cli-plugins
  3. download the "plugin", and save it as ~/.docker/cli-plugins/docker-compose (note: no .sh extension!)

    curl https://gist.githubusercontent.com/thaJeztah/b7950186212a49e91a806689e66b317d/raw/36d4c5854523502deed5b56842b0d34cd6ec0f70/docker-compose-plugin.sh > ~/.docker/cli-plugins/docker-compose 
  4. make it executable

    chmod +x ~/.docker/cli-plugins/docker-compose
  5. run the help command on the nightly docker cli to verify the plugin was installed

    ./docker help
    ...
    Commands:
      build                     Build an image from a Dockerfile
      compose     (Docker)      Define and run multi-container applications
      login                     Log in to a Docker registry
      logout                    Log out from a Docker registry
  6. enjoy!

    ./docker compose help
    Define and run multi-container applications with Docker.
    
    Usage:
      docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
      docker-compose -h|--help
    
    Options:
      -f, --file FILE             Specify an alternate compose file
                                  (default: docker-compose.yml)
      -p, --project-name NAME     Specify an alternate project name
#!/usr/bin/env bash
docker_cli_plugin_metadata() {
if [ -z "$DOCKER_COMPOSE_VERSION" ]; then
export DOCKER_COMPOSE_VERSION="$(docker-compose --version | cut -d " " -f 3 | cut -d "," -f 1)"
fi
local vendor="Docker"
local url="https://www.docker.com"
local description="Define and run multi-container applications"
cat <<-EOF
{"SchemaVersion":"0.1.0","Vendor":"${vendor}","Version":"${DOCKER_COMPOSE_VERSION}","ShortDescription":"${description}","URL":"${url}"}
EOF
}
case "$1" in
docker-cli-plugin-metadata)
docker_cli_plugin_metadata
;;
*)
exec "docker-$@"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment