Deploying a Redis Database
Redis is a fast, open-source, in-memory key-value data store used as a database, cache, and message broker. It is known for its high performance, support for various data structures, and ease of use, making it ideal for real-time applications and caching scenarios.
This guide explains how to deploy a Redis database to Klutch.sh using a Dockerfile, including installation, sample configuration, and persistent volume setup.
Prerequisites
- Docker installed (Download)
- Git and GitHub account
- Klutch.sh account
Getting Started: Sample Dockerfile
Create a Dockerfile
in your project root:
FROM redis:7.2-alpine
# Expose default Redis portEXPOSE 6379
# Optional: Add custom configuration# COPY ./redis.conf /usr/local/etc/redis/redis.conf# CMD ["redis-server", "/usr/local/etc/redis/redis.conf"]
Sample Usage
You can connect to your Redis database from any app using the following connection string:
redis://<APP_HOST>:6379
Replace <APP_HOST>
with the internal Klutch.sh service hostname or external IP as needed.
Deploying with Persistent Volumes
To ensure your Redis data persists across deployments and restarts, attach a persistent volume in Klutch.sh:
- Push your code (with Dockerfile) to a GitHub repository.
- Log in to Klutch.sh.
- Create a new project.
- Create a new app:
- Select your Redis GitHub repository and branch
- Choose the Dockerfile option when prompted
- Set service details and environment variables as needed
- Attach a persistent volume:
- In the “Volumes” section, add a new volume (e.g.,
redisdata
) - Mount path:
/data
- In the “Volumes” section, add a new volume (e.g.,
- Configure region, compute, and other settings as needed
- Click “Create” to deploy. Klutch.sh will build your Docker image, attach the volume, and start your Redis database.
Resources
Deploying Redis to Klutch.sh with a Dockerfile and persistent volumes ensures your data is safe and your database is production-ready.