Introduction to the steps of deploying redis in docker container

Introduction to the steps of deploying redis in docker container

1 redis configuration file

Official download: redis.conf

Path: In the container, it can generally be saved in the /etc/redis/redis.conf path

Detailed explanation of the configuration file, modify it according to the actual situation:

# The bind here means that only the specified network segment can access redis. If it is commented out, there is no such restriction. # bind 127.0.0.1

# The default port is 6379
port 6379

# daemonize indicates whether to execute as a daemon process. The execution in the container must be set to no
# If set to yes in the container, it will conflict with -d in docker run, causing startup failure. daemonize no

# protected-mode 
# Set to yes to enable protection mode, which means remote access is not possible. # Set to no to enable protection mode, which means remote access is possible. protected-mode no

# If you comment out, the default redis password is empty. # If you enable it, redis123 will be the redis login password requirepass redis123

# databases Set the number of databases to 16

#save
save 900 1
save 300 10
save 60 10000

# aof mode is not enabled by default, and RDB persistence is used by default appendonly yes # Change to yes to enable aof function appendfilename "appendonly.aof" # The name of the persistent file # appendfsync always # Each modification will be synced, which consumes performance appendfsync everysec # Execute sync once a second, and the data of 1s may be lost # appendfsync no # Do not execute sync, the operating system will automatically synchronize data

2 Docker command start

Startup Command

docker run -p 6379:6379 \
-v /Users/chenbinhao/redis_6379/data:/data \
-v /Users/chenbinhao/redis_6379/config/redis.conf:/etc/redis/redis.conf \
-d redis redis-server /etc/redis/redis.conf --appendonly yes

Parameter Description

-p port mapping, the default redis port is 6379

-v mainly maps files in two paths

/data The redis container will save the data in this path. The mapping here is to persist the data.

/etc/redis/redis.conf is the location where the custom configuration file is saved. The mapping here is to specify a custom configuration file at startup.

-d means running in the background as a daemon process. Note: daemonize no needs to be configured in the redis.conf configuration file, otherwise it will not be able to start successfully.

redis-server /etc/redis/redis.conf --appendonly yes starts the redis command. If you start with a custom configuration file, you need to execute this command.

Log view: docker logs containerID If the startup fails, use this command to view the failure log and debug according to the log.

3 docker-compose start

Directory Structure

├─reids_6379
│ ├─docker-compose.yml
│ ├─config
│ │ └─redis.conf
│ └─data
│ │ └─..

Configure docker-compose.yml file

version: '3'
services:
  redis:
    image: redis:latest
    restart: always
    ports:
      - "6379:6379"
    volumes:
      - "./data:/data"
      - "./config/redis.conf:/etc/redis/redis.conf"
    command: redis-server /etc/redis/redis.conf

Startup Command

Start: Execute docker-compse up -d in the directory where docker-compose.yml is located

Stop and delete: docker-compose down

This is the end of this article about the steps to deploy redis in docker containers. For more information about deploying 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:
  • How to quickly deploy Redis as a Docker container

<<:  MySQL Series Database Design Three Paradigm Tutorial Examples

>>:  CSS3 realizes the graphic falling animation effect

Recommend

mysql update case update field value is not fixed operation

When processing batch updates of certain data, if...

Methods and steps to access Baidu Maps API with JavaScript

Table of contents 1. Baidu Map API Access 2. Usin...

Using js to implement a number guessing game

Last week, the teacher gave me a small homework, ...

Use of SerialPort module in Node.js

Table of contents Purpose Module Installation Bas...

How to use lodop print control in Vue to achieve browser compatible printing

Preface This control will have a watermark at the...

JavaScript Regular Expressions Explained

Table of contents 1. Regular expression creation ...

Detailed tutorial on installing Python 3.6.6 from scratch on CentOS 7.5

ps: The environment is as the title Install possi...

Implementing carousel effects with JavaScript

This article shares the specific code for JavaScr...

Solution to input cursor misalignment in Chrome, Firefox, and IE

Detailed explanation of the misplacement of the in...

About Tomcat combined with Atomikos to implement JTA

Recently, the project switched the environment an...

Detailed explanation of monitoring NVIDIA GPU usage under Linux

When using TensorFlow for deep learning, insuffic...