DEV Community

Cover image for My Docker aliases / cheat-sheet
Dragoljub Bogićević
Dragoljub Bogićević

Posted on

My Docker aliases / cheat-sheet

I believe that most of us use docker and docker-compose on daily basis, so I decided to share part of my .bashrc file.
Maybe someone will find it useful...

Contents

  • General
  • Images
  • Containers
  • Networks
  • Volumes
  • Docker-Compose

Note about pattern I tried to follow for aliases:

  • for docker commands first letter is always d, for docker compose is dc
  • if command is related to images then next letter of alias is i, for containers is c and so on...
  • following this pattern I found it pretty easy to remember all aliases

General

alias dve="docker -v"
alias dl="docker login --username=dragol"

Explanation

dve - prints out current docker version
dl - docker login, will prompt you for password

Images

alias dil="docker images"
alias dip="docker image prune -f"

Explanation

dil - list all docker images available on my machine
dip - remove all dangling images -f is flag for force

Containers

alias dcl="docker ps"
alias dcla="docker ps -a"
alias dcp="docker container prune -f"
alias dci="docker inspect"
alias dciip="docker inspect -f \"{{ .NetworkSettings.IPAddress }}\""
alias dcs="docker start"
alias dcd="docker down"
alias dcr="docker restart"

Explanation

dcl - list running containers
dcla - list all containers
dcp - remove all dangling containers
dci - here you need to pass container id in order to get various information about particular container
dciip - returns container IP address
dcs - here you need to pass container id in order to start container
dcd - here you need to pass container id in order to stop container
dcr - here you need to pass container id in order to restart container

Networks

alias dnl="docker network ls"
alias dni="docker network inspect"
alias dnrm="docker network rm"
alias dnp="docker network prune -f"

Explanation

dnl - list networks
dni - here you need to pass network id in order to see it's details
dnrm - here you need to pass network id in order to delete it
dnp - remove all dangling networks

Volumes

alias dvc="docker volume create"
alias dvl="docker volume ls"
alias dvrm="docker volume rm"
alias dvp="docker volume prune -f"
alias dvi="docker volume inspect"

Explanation

dvc - here you need to pass volume name in order to create it
dvl - list volumes
dvrm - here you need to pass volume id in order to delete it
dvp - remove all dangling volumes
dvi - here you need to pass volumeid in order to see it's details

Docker-Compose

alias dcv="docker-compose -v"
alias dcu="docker-compose up"
alias dcd="docker-compose down"
alias dcb="docker-compose build --no-cache"
alias dcc="docker-compose config"

Explanation

dcv - prints out docker compose version
dcu - start docker compose
dcd - stop docker compose
dcb - new docker compose build from ground up
dcc - check if docker-compose.yml file is valid

Basically, this commands I used the most, I did not post here functions from my .bashrc file (~15), I used them for commands with more the one arguments. Feel free to use them and modify as needed.

Thank you for reading!

Top comments (7)

Collapse
 
padakipavan profile image
padaki-pavan

I suggest you to have a look at lazydocker. I use it allthe time, it's amazing.

Collapse
 
vhorvath profile image
Viktor Horvath

Nice post some of these are very useful when you Docker all day!

I want to point out one caveat. When you alias the command the <tab> completion defaults to the list of files in the current directory. Aliased commands do not know the context anymore. This is not a problem for the aliases that do not require a subject (most of them). However, with the rest you will need to lookup and type in the subject name / container id. You will also lose the ability to peek at the list as you type by hitting <tab>.

For instance, when you do docker container inspect <container-name> it takes this without alias: doc<tab> conta<tab> in<tab> <tab: listing of container names> and then continue typing partial container name <tab> to complete.

Tab completion also saves you from typos. Docker did a good job making sure you can use it wherever you need to.

Collapse
 
chrisf1031 profile image
Chris Ford

I'll definitely be trying this out. Awesome post!

Collapse
 
eenesusta profile image
Enes Usta

There is an application that I have developed to do this job. If you are interested, please review. github.com/enesusta/dcli

Collapse
 
bogicevic7 profile image
Dragoljub Bogićević

Did not try it, but by reading docs it looks great!

Collapse
 
andrewcathcart profile image
Andrew Cathcart

You have a typo for docker restart.

Collapse
 
bogicevic7 profile image
Dragoljub Bogićević

Happens all the time :) tnx