The host computer startup configuration file Redis Redis in Docker

CentOS 7.7 environment

Prerequisite: installed a Docker container, has pulled the mirror Redis

 

1. Create a directory store Redis profile

[root@localhost ~]# mkdir -p /usr/local/docker/redis/conf

2. Create Redis persistence directory 

mkdir -p /usr/local/docker/redis/data

 

3. download the configuration file and transmitted to the / usr / local / docker / redis / conf

redis.conf Download 1: official website profile redis.conf
redis.conf Download 2: Github's redis.conf

4. edit the configuration file (which may be edited prior to transmission after the / usr / local / docker / redis / conf)

# Port settings
port 6379

# Remote Access (commented bind 127.0.0.1; change the protected-mode yes to protected-mode no)
#bind 127.0.0.1
protected-mode no

# Daemon mode (non-background mode, daemonize yes redis way to start the configuration file will fail; if not no, docker will always fail to start because docker itself needs to run in the background, and this configuration option is to start the daemon, both conflict)
daemonize no

#redis persistence
yes appendOnly 

# specify the local database storage directory
dir ./

Other Profile Configuration Reference: redis.conf Configuration

Start testing found the back of the container, there is a downloadable configuration file to configure repl-diskless-load disabled reading will complain, near the 472 line, the repl-diskless-load disabled commented (may be a new configuration parameters, see specific comments Description):

*** FATAL CONFIG FILE ERROR ***
Reading the configuration file, at line 472
>>> 'repl-diskless-load disabled'
Bad directive or wrong number of arguments

 

5. Create a container, Profile Mapping

[root@localhost conf]# docker run -d -p 6379:6379 \
> -v /usr/local/docker/redis/conf/redis.conf:/etc/redis/redis.conf \
> -v /usr/local/docker/redis/data:/data \
> --privileged=true \
> --name myredis redis:latest \
> redis-server /etc/redis/redis.conf \
> --appendonly yes

Or line:

docker run -d -p 6379:6379 -v /usr/local/docker/redis/conf/redis.conf:/etc/redis/redis.conf -v /usr/local/docker/redis/data:/data --privileged=true --name myredis redis:latest redis-server /etc/redis/redis.conf --appendonly yes

 

Comment:

#docker start command
docker run

Start background #
-d
  
# host container port mapping
-p 6379: 6379


# Configuration file mapping, the container can be achieved successfully start the container change the actual purpose of the profile by changing the host configuration file
-v /usr/local/docker/redis/conf/redis.conf:/etc/redis/redis.conf

Persistent file # mount
-v / usr / local / Docker / Redis / Data: / Data
/ usr / local / My-Redis / Data host position is persisted file
/ data / files is the persistence of the vessel position (dir property values required and the same profile),

# Container inside the Linux kernel to use all the features of the host, docker container firewall completely open
--privileged = true

# Run Mirror redis, and after starting the container name named myredis
--name myredis Redis: Latest

# Profiles way to start the Redis
Redis-Server /usr/local/etc/redis/redis.conf

# Persistent
--appendonly yes

6. Connection Test

 

 

 7. Docker Redis into the container

  7.1 container ID check 

[root@localhost conf]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
9cac1dfcba0b        redis:latest        "docker-entrypoint..."   13 minutes ago      Up 13 minutes       0.0.0.0:6379->6379/tcp   myredis

  7.2 execute: docker exec -it container id / bin / bash

[root@localhost conf]# docker exec -it 9cac1dfcba0b /bin/bash
root@9cac1dfcba0b:/data# ls
appendonly.aof  dump.rdb
root@9cac1dfcba0b:/data# cd /etc/redis/
root@9cac1dfcba0b:/etc/redis# ls
redis.conf
root@9cac1dfcba0b:/etc/redis# 

  It can be found aof file and startup configuration file

  7.3 Exit Ctrl + d

 

 

Guess you like

Origin www.cnblogs.com/youngyajun/p/11915146.html