Docker shortcuts

After a while working with Docker, you get tired of always typing the relatively long command ‚docker‘ or of remembering more complicated commands. Thus, I was wondering how I can setup some aliases to make me more productive. I found a good references on github from where I was inspired and took or derived my shortcuts. The shortcuts consist of aliases and functions.

# Docker
alias d='docker'
# Get container process
alias dps='docker ps'
# Get process including stopped containers
alias dpsa='docker ps -a'
# Get images
alias di='docker images'
# Start container
dstart() { docker start $1; }
# Stop container
dstop() { docker stop $1; }
# Stop all running containers
dstopa() { docker stop $(docker ps); }
# Remove container
alias drm='docker rm'
# Remove image
alias drmi='docker rmi'
# Removing all stopped containers
drma() { docker rm $(docker ps -a -q); }
# Removing all images
drmia() { docker rmi $(docker images -q); }
# Getting the IP address
alias dip="docker inspect –format '{{ .NetworkSettings.IPAddress }}'"
# Build from dockerfile
db() { docker build -t=$1 .; }
# Enter into a running container with bash
dbash() { docker exec -it $1 /bin/bash; }

view raw


hosted with ❤ by GitHub

All these shortcuts have to be placed in the .bash_profile file. This file has to be created in the local user’s home if it  does not exist yet. In order to find out which is the user’s home type in cd ~ in the Docker client which will jump to this directory. Whenever the Docker client is launched, the file is loaded and all commands are executed. After that, all these shortcuts are available in the Docker client.