Docker builds Redis5.0 and mounts data

Docker builds Redis5.0 and mounts data

Record the process of building Redis5.0 with Docker and mounting data. The reference for building is from Docker Hub

1. Simple mounting of persistent data

docker run -d -p 6379:6379 --name redis \
-v /itwxe/dockerData/redis/data:/data \
redis:5.0.8 redis-server --appendonly yes

This only mounts the data. Redis has no password or other configurations, so anyone can connect to it. If the server is on the public network, it is extremely unsafe.

So as usual, I entered the container to find where the redis configuration file was, and then configured and mounted it. As a result, I found that there was no redis.conf file in the container.

It is mentioned in Docker Hub that you need to customize redis.conf to build the image using DockerFile.

Docker uses custom configuration to build redis image

2. Build an image through DockerFile and start it by specifying the configuration file

1. First go to the Redis official website to download a version that is consistent with the mirror version. My version is 5.0.8. Then unzip the file and upload redis.conf to the server.

2. Modify the redis.conf configuration. The main configuration is as follows. Modify it according to your needs.

# Modify background startup, the default is daemonize no, docker startup is the default, background startup will cause the container to exit daemonize no

# How long does it take for the client to be idle before disconnecting? The default value is 0 to disable this feature. timeout 0

# Set password, commented by default, uncomment and change to a custom password (mine is 123456)
requirepass 123456

# Listening ip, allowed access ip, default is 127.0.0.1, change to 0.0.0.0 (allow all server ip to access) or comment out bind 0.0.0.0

#Specify the listening port, the default is 6379, here I keep the default port 6379

# Whether to enable AOF persistence, the default is no
appendonly yes

# Modify the AOF and RBD storage path, the default is ./, change to /data
dir /data

# Modify the log storage path, the default is "", change it to "/data/redis_6379.log"
logfile "/data/redis_6379.log"

3. Create a Dockerfile file and add content. If you don’t know how to use Dockerfile, you can take a look at DockerFile to build an image.

FROM redis:5.0.8
COPY redis.conf /usr/local/etc/redis/redis.conf
CMD ["redis-server", "/usr/local/etc/redis/redis.conf"]

4. Build the image.

docker build -t itwxe/redis:5.0.8 .

Build a custom configuration redis image

5. Start the built image and mount the data.

docker run -d -p 6379:6379 --name redis \
-v /itwxe/dockerData/redis/data:/data \
itwxe/redis:5.0.8

You can see that the data is mounted normally.

Customize redis image automatically

At the same time, you can test the password and connect normally.

Customize redis container connection

This is the end of this article about building Redis 5.0 with Docker and mounting data. For more information about building Redis with 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:
  • Introduction to the steps of deploying redis in docker container
  • Docker installation and configuration steps for Redis image
  • Implementation steps for installing Redis container in Docker

<<:  HTML allows partial forced scroll bars to not destroy the overall style and layout

>>:  SQL fuzzy query report: ORA-00909: invalid number of parameters solution

Recommend

CSS sample code to achieve circular gradient progress bar effect

Implementation ideas The outermost is a big circl...

Pure CSS to achieve the effect of picture blinds display example

First, let me show you the finished effect Main i...

Example of implementing a virtual list in WeChat Mini Program

Table of contents Preface analyze Initial Renderi...

Detailed explanation of JavaScript's garbage collection mechanism

Table of contents Why do we need garbage collecti...

How to view image information in Docker

In this article, we will need to learn how to vie...

Appreciation of the low-key and elegant web design in black, white and gray

Among classic color combinations, probably no one...

What is Nginx load balancing and how to configure it

What is Load Balancing Load balancing is mainly a...

Detailed explanation of the initialization mechanism in bash

Bash Initialization Files Interactive login shell...

Implementing shopping cart function based on vuex

This article example shares the specific code of ...

6 ways to view the port numbers occupied by Linux processes

For Linux system administrators, it is crucial to...

Basic ideas for finding errors in Web front-end development

WEB development mainly consists of two interactio...

Javascript destructuring assignment details

Table of contents 1. Array deconstruction 2. Obje...