概要
みなさんこんにちはcandleです。今回はdockerコマンドを簡単に操作するためのエイリアスを紹介します。もちろん、僕が便利かなと思って作成したものなので、コピペしてもらい自由により使いやすくしてください。
前提
bashで作業している。zchでもcshでもちょっとカスタマイズすれば使えると思います。
dockerを使っている。
エイリアス一覧
ホームディレクトリにある.bash_profileを開いて、以下を記述しましょう。
# stop the running containers. You would pass the running container ids. # ex) dcstop 5c07dab43333 30jfeodd function dcstop(){ docker stop $@ } # stop all containers alias dcstopa='docker stop $(docker ps -a -q)' # remove the stopped containers. You would pass the stopped container ids. # ex) dcrm 5c07dab43333 30jfeodd999 function dcrm(){ docker rm $@ } # remove all stopped containers alias dcrma='docker rm $(docker ps -qf "status=exited") $(docker ps -qf "status=created")' # stop and remove all containers alias dcdel='dcstopa && dcrma' # show running containers alias dcps='docker ps' # show all containers alias dcpsa='docker ps -a' # show stopped containers alias dcpss='docker ps -f "status=exited"' # docker-compose up alias dcup='docker-compose up -d' # docker-compose down -v alias dcdown='docker-compose down -v' # show all docker images alias dci='docker images' # remove some images. You would pass the image ids. # ex) dcrmi d266fc618ebc 37bf53c81f1c function dcrmi(){ docker rmi $@ } # remove latest created images function dcrmli(){ dcrmi $(docker images -q | awk 'NR == 1 {print $0}') } # show all docker volulmes alias dcvls='docker volume ls' # remove some volumes. You would pass the volume names. # ex) dcvrm php-fpm nginx 3452380 function dcvrm(){ docker volume rm $@ } # login to the running container. You would pass the running container id. # ex) dcexec 5c07dab43333 function dcexec(){ docker exec -t -i $1 /bin/bash } # show cotainer logs. You would pass the container id # ex) dclogs 5c07dab43333 function dclogs(){ docker logs $1 } # watching cotainer logs. You would pass the container id # ex) dctail 5c07dab43333 function dctail(){ docker logs -f $1 }
まとめ
もしも、なにかこれが足りないよという意見などがありましたら、コメント欄、twitterで補足していただけると幸いです。