#!/bin/bash

docker_name=$1
PROGNAME="$(basename "$0")"



# ---------------
# Error Handling
# ---------------
set -e
trap 'catch $? $LINENO' EXIT
catch() {
#  echo "catching!"
  if [ "$1" = "1" ]; then
    # error handling goes here
    docker exec -ti "$docker_name" /bin/ash
    trap - ERR  
    #echo "Error $1 occurred on $2 in $PROGNAME"
  else
    docker exec -ti "$docker_name" /bin/bash
    trap - ERR
  fi
}
# ---------------
# Error Handling
# ---------------

if [ "$docker_name" == "" ]
then
  echo "$PROGNAME is expecting a container name"
  exit 1
fi

docker exec "$docker_name" /bin/bash > /dev/null ||  false # docker exec -ti "$docker_name" /bin/ash

