Using a Makefile to shorten commands

Photo by Kara Eads on Unsplash

Using a Makefile to shorten commands


You may already have known but I discovered that you can define a Makefile in which you can store your lengthy and commonly used commands. This feels like a step up from simple bash aliases. You could store a helpful Makefile into source control and share with your dev team.


Make sure you have make installed first in your machine. There are ton of tutorials online how to do so.

Let us see an example for creating shortcuts for our Docker commands. Like so:

    docker-compose up -d

    docker-compose down

    docker-compose exec web sh

Assuming I am in the same directory as the Makefile, I can use the command, make up to start my Docker services. Same goes with executing make down to shut them down and executing make shell to pop open a shell from my web container.

Closing Thoughts

Thanks to our Makefile, we no longer have to type lengthy commands. This article shed light more on the topic on why Makefiles are better than NPM scripts.