Skip to content

Commit

Permalink
Connect to running container if -c is used
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-wramner committed Jul 30, 2019
1 parent f21bffe commit f01102f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions setup.sh
Expand Up @@ -12,6 +12,7 @@ INFO=$(docker ps \
IMAGE_NAME=$(echo $INFO | awk '{print $1}')
CONTAINER_NAME=$(echo $INFO | awk '{print $2}')
DEFAULT_CONFIG_PATH="$(pwd)/config"
USE_CONTAINER=false

_update_config_path() {
VOLUME=$(docker inspect $CONTAINER_NAME \
Expand Down Expand Up @@ -98,14 +99,21 @@ _docker_image_exists() {
}

_docker_image() {
if ! _docker_image_exists "$IMAGE_NAME"; then
echo "Image '$IMAGE_NAME' not found. Pulling ..."
docker pull "$IMAGE_NAME"
fi
if [ "$USE_CONTAINER" = true ]; then
# Reuse existing container specified on command line
docker exec -ti "$CONTAINER_NAME" "$@"
else
# Start temporary container with specified image
if ! _docker_image_exists "$IMAGE_NAME"; then
echo "Image '$IMAGE_NAME' not found. Pulling ..."
docker pull "$IMAGE_NAME"
fi

docker run \
--rm \
-v "$CONFIG_PATH":/tmp/docker-mailserver \
-ti "$IMAGE_NAME" $@
fi
}

_docker_container() {
Expand All @@ -121,6 +129,7 @@ while getopts ":c:i:p:" OPT; do
case $OPT in
c)
CONTAINER_NAME="$OPTARG"
USE_CONTAINER=true # Container specified, connect to running instance
;;
i)
IMAGE_NAME="$OPTARG"
Expand Down

0 comments on commit f01102f

Please sign in to comment.