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