Skip to content

Instantly share code, notes, and snippets.

@giordanocardillo
Last active June 20, 2017 13:48
Show Gist options
  • Save giordanocardillo/3111bfd5543813227008f140201d7135 to your computer and use it in GitHub Desktop.
Save giordanocardillo/3111bfd5543813227008f140201d7135 to your computer and use it in GitHub Desktop.
Using composer with docker

Instructions

  1. Download the file composer to /usr/local/bin/composer

    1.1. curl -o /usr/local/bin/composer -L https://gist.githubusercontent.com/giordanocardillo/3111bfd5543813227008f140201d7135/raw/composer

  2. chmod a+x /usr/local/bin/composer to make executable

  3. Run composer

  4. Enjoy

set -e
IMAGE="composer/composer:alpine"
# Setup options for connecting to docker host
if [ -z "$DOCKER_HOST" ]; then
DOCKER_HOST="/var/run/docker.sock"
fi
if [ -S "$DOCKER_HOST" ]; then
DOCKER_ADDR="-v $DOCKER_HOST:$DOCKER_HOST -e DOCKER_HOST"
else
DOCKER_ADDR="-e DOCKER_HOST -e DOCKER_TLS_VERIFY -e DOCKER_CERT_PATH"
fi
# Setup volume mounts for context
if [ "$(pwd)" != '/' ]; then
VOLUMES="-v $(pwd):$(pwd)"
fi
# TODO: also check --file argument
if [ -n "$HOME" ]; then
VOLUMES="$VOLUMES -v $HOME:$HOME -v $HOME:/root" # mount $HOME in /root to share docker.config
fi
# Only allocate tty if we detect one
if [ -t 1 ]; then
DOCKER_RUN_OPTIONS="-t"
fi
if [ -t 0 ]; then
DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS -i"
fi
exec docker run --rm $DOCKER_RUN_OPTIONS $DOCKER_ADDR $VOLUMES -w "$(pwd)" $IMAGE "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment