Skip to content

Instantly share code, notes, and snippets.

@Nathanjms
Last active May 4, 2022 18:25
Show Gist options
  • Save Nathanjms/ccf00dca6da2e034b8ae34f2471daffd to your computer and use it in GitHub Desktop.
Save Nathanjms/ccf00dca6da2e034b8ae34f2471daffd to your computer and use it in GitHub Desktop.
Laravel `docker exec` Shortcuts

Laravel docker exec Shortcuts

Instead of constantly typing docker exec app [command], the above file can be used to speed this up.

How to run

This can either be ran as a file (e.g. bash dexec.sh), or could be added as a function into your zsh or bash config.

#!/bin/bash
if ! [ -z "$1" ]; then
echo "Container Name: $1"
container_name=$1
else
echo -n "Container Name: "
read container_name
echo
if [ -z "$container_name" ]; then
echo "Container Name is required, exiting..."
return 1
exit 1
fi
fi
echo -n "Command?
ci = composer install
mi = php artisan migrate
kg = php artisan key:generate
db = php artisan db:seed
at = php artisan user:grant-personal-access-token
pa = php artisan passport:install
ba = /bin/bash
> "
read input
if [ -z "$input" ]; then
echo "Command is required, exiting..."
return 1
exit 1
fi
case "$input" in
ci)
echo "Running composer install on container..."
docker exec $container_name composer install
;;
mi)
echo "Running php artisan migrate on container..."
docker exec $container_name php artisan migrate
;;
kg)
echo "Running php artisan key:generate on container..."
docker exec $container_name php artisan key:generate
;;
db)
echo "Running php artisan db:seed on container..."
docker exec $container_name php artisan db:seed
;;
at)
echo "Running php artisan user:grant-personal-access-token on container..."
docker exec -it $container_name php artisan user:grant-personal-access-token
;;
ba)
echo "Opening container in bash, type 'exit' to quit..."
docker exec -it $container_name /bin/bash
;;
pa)
echo "Running php artisan passport:install on container..."
docker exec $container_name php artisan passport:install
;;
*)
echo "Invalid argument provided, exiting..."
return 1
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment