Work faster from the command line with Docker and Django
If you’re anything like me, speed is important to you. If speed is important then you need to keep your keystrokes to a minimum. We define functions anytime we realize there’s a bit of code that’s potentially reusable. Well… we should do the same working from the command line.
While working with Docker and Django, there are a few commands that we need to run quite regularly.
docker-compose run web manage.py shell # or shell_plus
docker-compose run web manage.py makemigrations
docker-compose run web manage.py migrate
Well, those are quite a few words to type out each time we need to run them. What I do is to put some aliases in my bash/zsh script so that I can eliminate typing all of that stuff every time. Here’s what I’ve got configured.
This is good for Bash or ZSH, the syntax works in both.
# ~/.zshrc or ~/.bashrc
# Run docker-compose with just "dc"
# Run manage.py with just "dm"
alias dm="docker-compose run web python manage.py"
# Run makemigrations with just "dmm"
alias dmm="docker-compose run web python manage.py makemigrations"
# Run migrate with just "dmi"
alias dmi="docker-compose run web python manage.py migrate"
# Run shell_plus with just "dsp"
alias dsp="docker-compose run web python manage.py shell_plus"
# Run test with just "dt"
alias dt="docker-compose run web python manage.py test"
This was a quick one but I hope it helps someone else reduce their key strokes.
Share it with someone you think needs to speed up!