004-build-redis.sh 899 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. . mailcow.conf
  3. NAME="redis-mailcow"
  4. client() {
  5. docker exec -it ${NAME} /bin/bash -c "redis-cli"
  6. }
  7. if [[ ${1} == "--client" ]]; then
  8. client
  9. exit 0
  10. elif [[ ! -z ${1} ]]; then
  11. echo "Unknown parameter"
  12. exit 1
  13. fi
  14. echo "Stopping and removing containers with name tag ${NAME}..."
  15. if [[ ! -z $(docker ps -af "name=${NAME}" -q) ]]; then
  16. docker stop $(docker ps -af "name=${NAME}" -q)
  17. docker rm $(docker ps -af "name=${NAME}" -q)
  18. fi
  19. if [[ ! -z "$(docker images -q redis:${DBVERS})" ]]; then
  20. read -r -p "Found image locally. Delete local image and repull? [y/N] " response
  21. response=${response,,}
  22. if [[ $response =~ ^(yes|y)$ ]]; then
  23. docker rmi redis:${DBVERS}
  24. fi
  25. fi
  26. docker run \
  27. -v ${PWD}/data/db/redis/:/data/ \
  28. --network=${DOCKER_NETWORK} \
  29. --network-alias=redis \
  30. -h redis \
  31. --name=${NAME} \
  32. -d redis:${REDISVERS} --appendonly yes