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

Summary of special processing statements of MySQL SQL statements (must read)

1. Update the entire table. If the value of a col...

Summary of Common Terms in CSS (Cascading Style Sheet)

If you use CSS don't forget to write DOCTYPE, ...

Summary of important components of MySQL InnoDB

Innodb includes the following components 1. innod...

Example of troubleshooting method to solve Nginx port conflict

Problem Description A Spring + Angular project wi...

MySQL 8.0.13 installation and configuration tutorial under CentOS7.3

1. Basic Environment 1. Operating system: CentOS ...

Steps for Docker to build its own local image repository

1. Environment and preparation 1. Ubuntu 14.04 2....

Sample code for programmatically processing CSS styles

Benefits of a programmatic approach 1. Global con...

Two methods of MySql comma concatenation string query

The following two functions are used in the same ...

MySQL stored functions detailed introduction

Table of contents 1. Create a stored function 2. ...

Docker executes a command in a container outside the container

Sometimes we want to execute a command in a conta...