• 配置文件

docker-compose.yml

# docker-compose.yml文件的版本
version: "3"
# 管理的服务
services:
  redis:
    image: redis
    ports:
      # 端口映射
      - 6379:6379
    volumes:
      # 持久化 目录映射
      - "./redis/redis.conf:/usr/local/etc/redis/redis.conf"
      - "./redis/data:/data"
    command:
      # 执行的命令
      redis-server /usr/local/etc/redis/redis.conf

redis.conf

requirepass 123456
appendonly yes
daemonize no

在当前目录结构

├── docker-compose.yml
└── redis
    ├── data
    └── redis.conf
  • 运行
docker-compose up -d
  • 查看当前容器运行状态
docker ps -a
  • 测试redis
[root@localhost my_docker_compose]# docker exec -it cb59364dfb75 redis-cli -h 127.0.0.1 -p 6379 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> set test 123
OK
127.0.0.1:6379> get test
"123"
127.0.0.1:6379> exit
Last modification:February 13th, 2020 at 03:59 pm
如果觉得我的文章对你有用,请随意赞赏