📜  docker redis - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:00:29.214000             🧑  作者: Mango

Docker Redis - Shell/Bash

Introduction

Docker is a containerization platform that allows you to package your applications and their dependencies into portable containers. Redis is an open source, in-memory data structure store that is used as a database, cache, and message broker. By using Docker and Redis together, you can create a scalable and portable solution for your data storage needs.

This guide will show you how to use Docker to run a Redis container using the Shell/Bash command line interface.

Prerequisites

Before you begin, make sure you have the following:

  • A Docker installation (https://www.docker.com/get-started)
  • A basic understanding of Redis (https://redis.io/topics/introduction)
Steps
1. Pull the Redis image

The first step is to pull the Redis image from the official Docker Hub repository.

docker pull redis
2. Run the Redis container

Once the image is downloaded, you can run the Redis container using the docker run command.

docker run --name my-redis-container -d redis

This command will create a new container from the Redis image, and the -d flag detaches the container from the terminal, allowing it to run in the background. The --name flag assigns a name to the container so that it can be easily referenced later.

3. Verify the Redis container is running

To verify that the Redis container is running, you can use the docker ps command.

docker ps

This command will list the running containers on your system, and you should see the newly created Redis container in the output.

4. Connect to the Redis container

To connect to the Redis container, you can use the docker exec command.

docker exec -it my-redis-container redis-cli

This command will open a terminal session inside the Redis container and start the Redis command line interface.

5. Use Redis

Now that you're connected to the Redis container, you can start using Redis. Here are a few basic commands to get you started:

# Set a key-value pair
set mykey "hello world"

# Retrieve a value by key
get mykey

# Increment a counter by 1
incr mycounter
Conclusion

By using Docker and Redis, you can create a portable and scalable solution for your data storage needs. With just a few commands, you can create a Redis container and start using Redis to store and retrieve data.