1.创建挂载目录
#创建挂载目录
mkdir -p /data/redis
2.创建yml文件
vim /data/redis/docker-compose.yml
填入配置
version: '3'
services:
redis:
image: redis:6.2.6
container_name: redis
restart: always
ports:
- 6379:6379
volumes:
- /data/redis/redis.conf:/etc/redis/redis.conf
- /data/redis/data:/data
- /data/redis/logs:/logs
command: ["redis-server","/etc/redis/redis.conf"]
3.创建挂载的配置文件
vim /data/redis/redis.conf
version: '3'
services:
redis:
image: redis:6.2.6
container_name: redis
restart: always
ports:
- 6379:6379
volumes:
- /data/redis/redis.conf:/etc/redis/redis.conf
- /data/redis/data:/data
- /data/redis/logs:/logs
command: ["redis-server","/etc/redis/redis.conf"]
4.到对应目录下启动容器
cd /data/redis
docker-compose up -d
#如果需要强制重新构建
docker-compose up --force-recreate -d