Skip to content

Instantly share code, notes, and snippets.

@mattbell87
Last active February 28, 2024 02:33
Show Gist options
  • Save mattbell87/d93d9d0e1a9ef992b63bacd5ba8edc4e to your computer and use it in GitHub Desktop.
Save mattbell87/d93d9d0e1a9ef992b63bacd5ba8edc4e to your computer and use it in GitHub Desktop.
Run a command in a container
#!/bin/bash
# Link this file to /usr/local/bin/<command-name>
exec=$(basename $0)
container="container"
user="root"
dockerCmdNonInteractive="docker exec -u $user $container"
dockerCmd="docker exec -it -u $user $container"
display="🫙 $user@$container:$($dockerCmdNonInteractive pwd)\$ $exec $*"
# Custom commands
case $exec in
"phpcs")
# Handle phpcs command
$dockerCmdNonInteractive ~/.composer/vendor/bin/phpcs $*
;;
"phpcbf")
# Handle phpcbf command
$dockerCmdNonInteractive ~/.composer/vendor/bin/phpcbf $*
;;
*)
# Any other command
echo $display
$dockerCmd $exec $*
;;
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment