Skip to content

Instantly share code, notes, and snippets.

@thomet

thomet/README.md

Last active Oct 5, 2020
Embed
What would you like to do?

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 `docker-machine ip` --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
You can’t perform that action at this time.