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

CSS float property diagram float property details

Using the CSS float property correctly can become...

nginx+tomcat example of accessing the project through the domain name

I was curious about how to access the project usi...

Installation and configuration tutorial of MySQL 8.0.16 under Win10

1. Unzip MySQL 8.0.16 The dada folder and my.ini ...

VMware and CentOS system installation method to reset the root password

Today's Tasks 1. Choice of Linux distribution...

How to view and clean up Docker container logs (tested and effective)

1. Problem The docker container logs caused the h...

Sample code for implementing radar chart with vue+antv

1. Download Dependency npm install @antv/data-set...

Simple writing of MYSQL stored procedures and functions

What is a stored procedure Simply put, it is a se...

How to quickly build your own server detailed tutorial (Java environment)

1. Purchase of Server 1. I chose Alibaba Cloud...

5 commonly used objects in JavaScript

Table of contents 1. JavaScript Objects 1).Array ...

How to implement Linux deepin to delete redundant kernels

The previous article wrote about how to manually ...

Detailed tutorial for installing influxdb in docker (performance test)

1. Prerequisites 1. The project has been deployed...

How to clean up the disk space occupied by Docker

Docker takes up a lot of space. Whenever we run c...