Handy Docker alias command example

Shortcut your typing and speed up your deployments.

Add the following to your ~/.bashrc

NOTE .bashrc is located in the root of your home directory.

1
2
3
4
#AR alias
alias dcp='docker compose --profile'
alias dps='docker ps'
alias dc='docker compose'

OR create this dandy little bash script to auto append a group of alias commands.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash

# Define the lines to append
lines_to_append="#AR alias
alias dcp='docker compose --profile'
alias dps='docker ps'
alias dc=docker compose'"

# Check if the lines already exist in the .bashrc file to avoid duplicates
if ! grep -Fxq "$lines_to_append" ~/.bashrc; then
  # Append the lines to the .bashrc file
  echo "$lines_to_append" >> ~/.bashrc
  echo "Successfully appended the following lines to ~/.bashrc:"
  echo "$lines_to_append"
else
  echo "The specified lines already exist in ~/.bashrc. No changes were made."
fi

echo "Remember to source your .bashrc file or open a new terminal for the changes to take effect:"
echo "  source ~/.bashrc"
Licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy