docker-compose搭建redis服务
1.首先准备所需文件
bash
mkdir data
touch redis.conf
touch docker-compose.yaml
# 这个结构
[root@iZbp16ukkrjo2m3jyyo3tfZ redis]# ls
data docker-compose.yaml redis.conf
2.编辑redis.conf
bash
bind 0.0.0.0
port 6379
# tcp-backlog 511
timeout 0
tcp-keepalive 0
logfile ""
supervised no
3.编辑docker-compose.yaml
yaml
version: "3.1"
services:
redis:
image: redis
container_name: redis
restart: always
environment:
TZ: Asia/Shanghai
ports:
- 6379:6379
command: /usr/local/bin/redis-server /usr/local/etc/redis/redis.conf
restart: always
volumes:
- ./redis.conf:/usr/local/etc/redis/redis.conf:rw
- ./data:/data
4.启动
bash
docker-compose -f docker-compose.yaml up -d