Skip to content

Instantly share code, notes, and snippets.

@hyacinthus
Created February 4, 2017 02:25
Show Gist options
  • Save hyacinthus/24a537938e8402df997ab31b6a97d891 to your computer and use it in GitHub Desktop.
Save hyacinthus/24a537938e8402df997ab31b6a97d891 to your computer and use it in GitHub Desktop.
docker
# tmp mysql
sudo docker run --name play_mysql -p 3310:3306 -v /home/ubuntu/mysql_data/play:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7.17
# compose status
alias docker-stats='docker-compose ps|grep ${PWD##*/}|awk '\''{printf("%s ",$1)}'\''|xargs docker stats'
# ip
function docker-ips() {
(
echo 'CONTAINER ID|IMAGE|COMMAND|CREATED|STATUS|IP|PORTS|NAMES';
# truncating Id to 12 chars is docker ps default
# truncating StartedAt to 19 gives seconds resolution: "2016-11-15T12:57:56"
# space before `{{end}}` intentional, to separate if you have multiple networks with IP(?)
docker ps --quiet "$@" | xargs --no-run-if-empty docker inspect --format='{{printf "%.12s" .Id}}|{{.Config.Image}}|{{.Config.Cmd}}|{{printf "%.19s" .State.StartedAt}}|{{.State.Status}}|{{range $net, $conf := .NetworkSettings.Networks}}{{$net}}:{{$conf.IPAddress}} {{end}}|{{.NetworkSettings.Ports}}|{{.Name}}'
) | column -t -s '|'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment