Dockerを便利に使うためのalias | SOTA を参考にさせていただきながら自分なりのエイリアスを作ってみた。
.bashrc
# ------------------------------------
# Docker aliases
# ------------------------------------
alias d="docker"
# Get the latest container ID
alias dl="docker ps --latest --quiet"
# List containers
alias dps="docker ps"
# List containers including stopped containers
alias dpa="docker ps --all"
# List images
alias di="docker images"
# List images including intermediates
alias dia="docker images --all"
# Tree images including intermediates
alias dit="docker images --tree"
# Get an IPaddress of a container
alias dip="docker inspect --format '{{ .NetworkSettings.IPAddress }}'"
# Run a daemonized container
alias drd="docker run --detach --publish-all"
# Run an interactive container
alias dri="docker run --interactive --tty --publish-all"
# Remove all containers
alias drm='docker rm $(docker ps --all --quiet)'
# Remove all images
alias drmi='docker rmi $(docker images --quiet)'
# Remove all containers and images by force
alias dclean='docker kill $(docker ps --all --quiet); drm; drmi;'
# List all aliases relating to docker
dalias() { alias | grep 'docker' | sed "s/^\([^=]*\)='\(.*\)'/\1 => \2/"| sed "s/'\\\'//g"; }
※) 最後の /\1 =>
の部分は スペース1+タブ1
にしてみました。
$ dalias
alias d => docker
alias dclean => docker kill $(docker ps --all --quiet); drm; drmi;
alias di => docker images
alias dia => docker images --all
alias dip => docker inspect --format '{{ .NetworkSettings.IPAddress }}'
alias dit => docker images --tree
alias dl => docker ps --latest --quiet
alias dpa => docker ps --all
alias dps => docker ps
alias drd => docker run --detach --publish-all
alias dri => docker run --interactive --tty --publish-all
alias drm => docker rm $(docker ps --all --quiet)
alias drmi => docker rmi $(docker images --quiet)