DockerAliases

nicolaw 23rd March 2018 at 1:05pm
Bash Docker
docker-compose () {
  declare -a env args
  declare arg=""
  while [[ $# -ge 2 ]] ; do
    if [[ "$1" == "-e" ]] ; then
      env+=("$1" "$2") ; shift
    else
      args+=("$1")
    fi
    shift
  done
  set -x
  docker run \
    --rm \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v "$PWD:/rootfs/$PWD" \
    -w "/rootfs/$PWD" \
    $([[ ! -e env-file ]] || echo '--env-file env-file') \
    "${env[@]}" \
    docker/compose:1.19.0 \
    "${args[@]}"
  { set +x; } 2>/dev/null
}

dry () {
  docker run \
    --rm \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -it \
    moncho/dry \
    "$@"
}

docker-gc () {
  docker run \
    --rm \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v /etc:/etc:ro \
    -e GRACE_PERIOD_SECONDS=60 \
    -e FORCE_CONTAINER_REMOVAL=1 \
    -e FORCE_IMAGE_REMOVAL=1 \
    spotify/docker-gc \
    "$@"
}