Created
December 11, 2019 09:39
-
-
Save thetutlage/a32731df7ea5dbc9f93b17bb3d203c03 to your computer and use it in GitHub Desktop.
Making `docker-compose exec` faster by proxying it via `docker exec`. Courtesy (https://github.com/docker/compose/issues/4748#issuecomment-561438269)
This file contains hidden or 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
#!/usr/bin/env bash | |
docker-compose-exec() { | |
local ARG='' | |
local ARGS='' | |
local COUNT=0 | |
local DIR=$(basename $(pwd)) | |
for ARG in "$@"; do | |
case $ARG in | |
-*) | |
ARGS="$ARGS $ARG" | |
;; | |
*) | |
# first positional arg is container name, replace with container id | |
if [ $COUNT == 0 ]; then | |
ARG=$(docker ps -q --filter "name=${DIR}_${ARG}") | |
fi | |
ARGS="$ARGS $ARG" | |
COUNT=$((COUNT+1)) | |
;; | |
esac | |
done | |
docker exec -it $ARGS | |
} | |
docker-compose-exec "$1" "$2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use it as
./docker-exec.sh app "npm install some-package"