Connect to running container if -c is used

This commit is contained in:
Erik Wramner 2019-07-28 14:33:52 +02:00
parent f21bffe322
commit f01102fd34

View file

@ -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 \
@ -98,14 +99,21 @@ _docker_image_exists() {
}
_docker_image() {
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() {
@ -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"