ssvc-rimsting-vote/run-docker.sh

43 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# Set image name and tag
IMAGE_NAME="ssvc-rimsting-vote"
TAG="latest"
# Check if the image exists
if [[ "$(docker images -q ${IMAGE_NAME}:${TAG} 2> /dev/null)" == "" ]]; then
echo "Image ${IMAGE_NAME}:${TAG} not found. Building it first..."
./build-docker.sh
# Exit if build failed
if [ $? -ne 0 ]; then
echo "Failed to build the image. Exiting."
exit 1
fi
fi
# Run the container
echo "Starting container from image ${IMAGE_NAME}:${TAG}..."
echo "The application will be available at http://localhost:3000"
# Stop any existing container with the same name
CONTAINER_NAME="ssvc-rimsting-vote"
if [ "$(docker ps -aq -f name=${CONTAINER_NAME})" ]; then
echo "Stopping existing container..."
docker stop ${CONTAINER_NAME} > /dev/null
docker rm ${CONTAINER_NAME} > /dev/null
fi
# Run the container with data volume mounted
docker run -d \
--name ${CONTAINER_NAME} \
-p 3000:3000 \
-v "$(pwd)/data:/app/data" \
-e "ADMIN_PASSWORD=${ADMIN_PASSWORD:-schafwaschener-segelverein-admin}" \
--restart unless-stopped \
${IMAGE_NAME}:${TAG}
echo "Container started successfully!"
echo "To view logs: docker logs ${CONTAINER_NAME}"
echo "To stop: docker stop ${CONTAINER_NAME}"