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

Summary of Linux user groups and permissions

User Groups In Linux, every user must belong to a...

Install MySQL5.5 database in CentOS7 environment

Table of contents 1. Check whether MySQL has been...

A Brief Analysis of MySQL - MVCC

Version Chain In InnoDB engine tables, there are ...

Detailed explanation of several examples of insert and batch statements in MySQL

Table of contents Preface 1.insert ignore into 2....

React implements infinite loop scrolling information

This article shares the specific code of react to...

Linux parted disk partition implementation steps analysis

Compared with fdisk, parted is less used and is m...

Vue implements tab navigation bar and supports left and right sliding function

This article mainly introduces: using Vue to impl...

Record of the actual process of packaging and deployment of Vue project

Table of contents Preface 1. Preparation - Server...

How to get the height of MySQL innodb B+tree

Preface The reason why MySQL's innodb engine ...

Use of docker system command set

Table of contents docker system df docker system ...

How to use display:olck/none to create a menu bar

The effect of completing a menu bar through displ...

Detailed explanation of the middleman mode of Angular components

Table of contents 1. Middleman Model 2. Examples ...

Several ways to clear arrays in Vue (summary)

Table of contents 1. Introduction 2. Several ways...

React realizes secondary linkage (left and right linkage)

This article shares the specific code of React to...