24
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

自分的Docker用エイリアス

Posted at

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)
24
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?