docker+docker compose 部署Redis

1. Preparing the Environment

System Tools version Remark
CentOS 7 Configuration: 4-core 8G 256G
Docker 18.09.4
Docker-compose 1.23.2 Reference: CentOS7 installation Docker-compose recommendations

2. Prepare redis profile

We will start redis way through the configuration file, so you need to edit redis.conf

First conf template provided by the official download to a local directory

  curl -O http://download.redis.io/redis-stable/redis.conf

Get to redis.conf file
Here Insert Picture Description

Line 61: Note the bind
81 lines: protected-mode no change

3.编写docker-compose-redis.yml

version: '2'
services:
  #redis容器
  redis:
    #定义主机名
    container_name: myredis
    #使用的镜像
    image: redis:5.0.2
    #容器的映射端口
    ports:
      - 6379:6379
    command: redis-server /etc/conf/redis.conf
    #定义挂载点
    volumes:
      - ./data:/data
      - ./conf:/etc/conf
    #环境变量
    privileged: true
    environment:
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8

4. Start the container

Console Enter the following command:

 docker-compose -f docker-compose-redis.yml  up -d

When you finish entering the command docker psconfirm whether the vessel started successfully
Here Insert Picture Description
into the vessel, view the log

docker logs --tail=300 -f myredis 

Here Insert Picture Description
This represents the emergence of a successful start.

Note that the virtual machine need to open ports or turn off the firewall, to access external redis.

Published 32 original articles · won praise 26 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_28540443/article/details/104732656