Skip to content

Instantly share code, notes, and snippets.

@glaucomunsberg
Created November 28, 2023 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glaucomunsberg/aafcb9eb0500144fdad1cfa2ba4d2640 to your computer and use it in GitHub Desktop.
Save glaucomunsberg/aafcb9eb0500144fdad1cfa2ba4d2640 to your computer and use it in GitHub Desktop.
bash_profile with alias to docker compose commands
# past content bellow and and reload source
# $ nano ~/.bash_profile
# $ source ~/.bash_profile
# Command '$ dcu container_name' alias to '$ docker compose up -d container_name'
# Command '$ dcs container_name' alias to '$ docker compose stop container_name'
execute_dcs() {
if [ -z "$1" ]; then
echo "Usage: dcs <container_name>"
return 1
fi
local container_name="$1"
# Check if Docker Compose is installed
if ! command -v docker compose > /dev/null 2>&1; then
echo "Docker Compose is not installed. Please install it first."
return 1
fi
# Stop the specified container using Docker Compose
if [ -n "$1" ]; then
docker compose stop "$container_name"
return 1
else
docker compose down
return 1
fi
}
execute_dcu() {
if [ -z "$1" ]; then
echo "Usage: dcs <container_name>"
return 1
fi
local container_name="$1"
# Check if Docker Compose is installed
if ! command -v docker compose > /dev/null 2>&1; then
echo "Docker Compose is not installed. Please install it first."
return 1
fi
# Stop the specified container using Docker Compose
if [ -n "$1" ]; then
docker compose up -d "$container_name"
return 1
else
docker-compose up -d
return 1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment