Last active
February 28, 2024 02:33
-
-
Save mattbell87/d93d9d0e1a9ef992b63bacd5ba8edc4e to your computer and use it in GitHub Desktop.
Run a command in a container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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