Hitchhiker’s Guide to Docker Shortcuts

In todays tech world one tool has become very popular semi-recently. Of course, I am speaking of course docker. If you need something deployed, “who are you going to call?”… DOCKER. Docker is a open-source plat for for developers build, and run applications almost anywhere. I have been working with docker for the past 6 months and I have noticed that I type certain commands fairly frequently and it gets tiresome to type again, and again… so I have started to alias them. Here are some of my favorites.

Terminator Commands

alias docker-stop=’docker stop $(docker ps -a -q)’
alias docker-rm=’docker rm $(docker ps -a -q)’
alias docker-ps-clean=’docker-stop && docker-rm’

Terminator commands provide us the ability to stop and remove all of our containers. I used at the very before I learned about compose to clean up my local environments. Docker compose has this ability but it only removes items that have been designated in your docker-compose.yml

Fabuloso Commands

alias docker-rmi=’docker rmi $(docker images -a -q)’
alias docker-clean-images=’docker rmi $(docker images -a | grep none | awk ‘{print $3}’)’

These commands really helped clean my environments after a build that failed or did not fully clean after itself. The first command will remove all of your images. The second command will clean all the pesky `none` images that sometimes appears. I like to run the second command after any build especially if it fails.

Docker Compose

alias compose=’docker-compose’

The docker compose alias is not that fancy, but after typing docker-compose 20 time you will want to shorten it.

Follow your Logs

alias docker-logs=’docker logs -f’
alias compose-logs=’docker-compose logs -f’

For the logs this might not be necessary for the normal docker but for compose it becomes very handy.

If you have any alias that you would like to share please post them in the comments below.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.