redis-cli-docker-compose
Easily set up a Redis instance for your application using Docker Compose. This guide provides a simple Docker Compose file to run Redis, ideal for development and testing environments.
Redis CLI Docker Compose
Introduction to Redis and Docker Compose
This page provides a straightforward Docker Compose configuration to set up a Redis instance. Docker Compose is a powerful tool for defining and running multi-container Docker applications. By using a docker-compose.yml
file, you can easily manage the lifecycle of your Redis service, making it ideal for development, testing, and even simple production deployments.
Redis Docker Compose Configuration
Below is a sample docker-compose.yml
file that defines a single service for Redis. This configuration specifies the Redis image to use, sets a container name, configures environment variables, defines network settings, and maps ports for external access. It also includes basic logging configurations to manage disk space.
version: "3.7"
services:
redis-server:
image: redis:7.0
container_name: redis-server
environment:
- DOCKERHUB_DOCS=https://hub.docker.com/_/redis
networks:
- app
ports:
- 6379:6379
logging:
driver: "json-file"
options:
max-size: "1m"
networks:
app:
name: app
Explanation of the Docker Compose File
- version: "3.7": Specifies the Docker Compose file format version.
- services:: Defines the services (containers) that make up your application.
- redis-server:: The name of the Redis service.
- image: redis:7.0: Uses the official Redis image version 7.0 from Docker Hub.
- container_name: redis-server: Assigns a specific name to the container for easier identification.
- environment:: Sets environment variables within the container.
DOCKERHUB_DOCS
is an example, often used for linking to documentation. - networks:: Defines the network the service will connect to. Here, it's a custom network named
app
. - ports:: Maps ports from the host machine to the container.
6379:6379
exposes Redis on the default port. - logging:: Configures how logs are handled. This example uses a JSON file driver with a maximum size of 1MB per file.
- networks: app: name: app: Defines the custom network named
app
.
How to Use This Docker Compose File
To use this configuration:
- Save the content above into a file named
docker-compose.yml
. - Ensure you have Docker and Docker Compose installed on your system.
- Open your terminal, navigate to the directory where you saved the file, and run the command:
docker-compose up -d
. - To stop the Redis container, run:
docker-compose down
.
This setup provides a quick and efficient way to get a Redis server running for your projects.