Skip to content

Instantly share code, notes, and snippets.

@thomet
Last active December 20, 2021 14:55
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 thomet/a444d8cd84c08a50eea81ae32dbc1644 to your computer and use it in GitHub Desktop.
Save thomet/a444d8cd84c08a50eea81ae32dbc1644 to your computer and use it in GitHub Desktop.

You need to have you docker host running with docker-machine as default

Install

  1. Install mycli (https://www.mycli.net/)

brew install mycli

  1. Clone plugin

git clone https://gist.github.com/a444d8cd84c08a50eea81ae32dbc1644.git $ZSH_CUSTOM/plugins/connect-docker-db

  1. Enable plugin in ~/.zshrc

plugins=(.. connect-docker-db)

Usage

> connect-docker-db container-name-with-mysql

Note: You can use <tab> key to show all running containers to select one after the commant connect-docker-db

#compdef connect-docker-db
#autoload
local -a _1st_arguments
_1st_arguments=(${(f)${:-"$(docker ps --format {{.Names}})"$'\n'}})
_describe "connect-docker-db" _1st_arguments
function docker-database-port() {
docker port $1 3306 | cut -d ":" -f2
}
function connect-docker-db() {
mycli --host localhost --port `docker-database-port $1` --user root
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment