DEV Community

jacob
jacob

Posted on

Make your own docker command!

I saw this post about a custom cli app to make it just a little nicer to quickly shell in to a local docker container:

And I thought, what if instead of a brand new command, it was part of the docker cli? It's not well advertised, but you can! So I installed it as a custom docker command. Official docs here.

There are a couple rules.

  1. Where does the script go? I wanted to run docker goto. The easiest choice for me was ~/.docker/cli-plugins/docker-goto. Whatever subcommand name you want, just prefix it with "docker-"

  2. You must have a subcommand called "docker-cli-plugin-metadata". When I run docker goto docker-cli-plugin-metadata, it has to output specific json. This block is enough:

    if [[ "$1" == "docker-cli-plugin-metadata" ]]; then
    cat << HERE
    {
      "SchemaVersion": "0.1.0",
      "Vendor": "example.com",
    }
    HERE
    exit
    fi
    
  3. Make it executable: chmod +x ~/.docker/cli-plugins/docker-goto

Now you can make it do whatever you want! Full code in this gist.

Top comments (2)

Collapse
 
solvingj profile image
Jerry •

The link to the official docs is broken.

Collapse
 
djeikyb profile image
jacob •

😣 i guess they're getting rid of this? github.com/docker/cli/commit/459c6...