Detailed steps to use Redis in Docker

Detailed steps to use Redis in Docker

1. Introduction

This article will show you how to explore Redis using Docker. We can run Docker commands in Docker for Windows, Docker for mac, or Linux mode.

This article is based on Docker for mac.

2. View available Redis versions

You can view the Redis image in the image repository:

3. Get the image

Use the following command to pull the latest official version of the image:

docker pull redis:latest 

4. View local image

Use the following command to check whether the Redis image has been installed:

docker images 

In the picture we can see that we have installed the latest version of the Redis image.

5. Run the container

We give the container a name docker-redis, expose port 6379 (the default value for Redis), and run the container using the following command:

docker run -d -p 6379:6379 --name docker-redis redis 

-p 6379:6379: maps the 6379 port of the container service to the 6379 port of the host machine. The outside world can directly access the Redis service through the host ip:6379.

You can use the following command to view the running information of the container to determine whether the container is running successfully:

docker ps 

You can also view the log output by running the following command:

docker logs docker-redis 

6. Run Redis CLI in the container

Next, we connect to the redis service by running redis-cli in the container. We will start a new interactive session with the -it option in the running container and use it to run redis-cli:

docker exec -it docker-redis /bin/bash 

Now that we are connected to the container, let's run redis-cli:

root@517350f4f2bb:/data# redis-cli

Now we can run some basic Redis commands:

7. Clean up the container

Let's stop the docker-redis container and remove it:

docker stop docker-redis
docker rm docker-redis

Summarize

This is the end of this article about using Redis in Docker. For more information about using Redis in Docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Docker starts Redis and sets the password
  • How to deploy MySQL and Redis services using Docker
  • Detailed explanation of how Docker containers use services such as mongod/redis on the host
  • Detailed steps for installing Tomcat, MySQL and Redis with Docker
  • How to deploy stand-alone Pulsar and clustered Redis using Docker (development artifact)
  • Detailed explanation of persistent storage of redis under docker

<<:  MySQL performance optimization: how to use indexes efficiently and correctly

>>:  Specific usage of fullpage.js full screen scrolling

Recommend

Implementation of mysql decimal data type conversion

Recently, I encountered a database with the follo...

Example analysis of interval calculation of mysql date and time

This article uses an example to describe the inte...

Teach you how to insert 1 million records into MySQL in 6 seconds

1. Idea It only took 6 seconds to insert 1,000,00...

How to use Nginx to proxy multiple application sites in Docker

Preface What is the role of an agent? - Multiple ...

How to query the intersection of time periods in Mysql

Mysql query time period intersection Usage scenar...

Implement a simple data response system

Table of contents 1. Dep 2. Understand obverser 3...

jQuery manipulates cookies

Copy code The code is as follows: jQuery.cookie =...

MySQL 8.0.13 manual installation tutorial

This article shares the manual installation tutor...

Solve the error problem caused by modifying mysql data_dir

Today, I set up a newly purchased Alibaba Cloud E...

A brief understanding of the relevant locks in MySQL

This article is mainly to take you to quickly und...

Vue3 manual encapsulation pop-up box component message method

This article shares the specific code of Vue3 man...

Do not start CSS pseudo-class names with numbers

When newbies develop div+css, they need to name t...

Pricing table implemented with CSS3

Result: Implementation Code html <div id="...