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

Detailed tutorial on installing Nginx 1.16.0 under Linux

Because I have been tinkering with Linux recently...

Introduction to ufw firewall in Linux

Let's take a look at ufw (Uncomplicated Firew...

How to use Docker to build a development environment (Windows and Mac)

Table of contents 1. Benefits of using Docker 2. ...

CSS positioning layout (position, positioning layout skills)

1. What is positioning? The position attribute in...

Example code of how CSS matches multiple classes

CSS matches multiple classes The following HTML t...

Detailed steps to expand LVM disk in Linux

1. Add a hard disk 2. Check the partition status:...

Defining the minimum height of the inline element span

The span tag is often used when making HTML web p...

Detailed explanation of CSS BEM writing standards

BEM is a component-based approach to web developm...

MySQL query optimization: a table optimization solution for 1 million data

1. Query speed of two query engines (myIsam engin...

Vue-cli creates a project and analyzes the project structure

Table of contents 1. Enter a directory and create...

JavaScript Factory Pattern Explained

Table of contents Simple Factory Factory Method S...

Detailed explanation of the interaction between React Native and IOS

Table of contents Prerequisites RN passes value t...