Docker安装Redis

本文详细介绍如何使用Docker和docker-compose.yml文件快速部署Redis容器。通过配置文件设置主机名、镜像版本、端口映射、数据持久化路径及环境变量等参数,实现Redis服务的高效启动。文中还提供了启动日志及命令行操作示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Docker安装RabbitMQ
 

前置条件

请先安装Docker 

创建docker-compose.yml文件

version: '2'
services:

  #redis容器
  redis:
    #定义主机名
    hostname: myredis
    #使用的镜像
    image: redis:5.0.2
    #容器的映射端口
    ports:
      - 6381:6379
    restart: always
    #定义挂载点
    volumes:
      - ./redis/data:/data
    #环境变量
    environment:
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8

将以上文件保存为docker-compose.yml文件

启动docker-compose脚本

docker-compose up

启动日志

AppledeMacBook-Pro:~ apple$ cd ~/Docker/Workspace/
AppledeMacBook-Pro:Workspace apple$ ls
activemq	rabbitmq
AppledeMacBook-Pro:Workspace apple$ mkdir redis
AppledeMacBook-Pro:Workspace apple$ cd redis/
AppledeMacBook-Pro:redis apple$ ls
AppledeMacBook-Pro:redis apple$ vim docker-compose.yml
AppledeMacBook-Pro:redis apple$ docker-compose up
Creating network "redis_default" with the default driver
Pulling redis (redis:5.0.2)...
5.0.2: Pulling from library/redis
a5a6f2f73cd8: Pull complete
a6d0f7688756: Pull complete
53e16f6135a5: Pull complete
b761e99e9c9c: Pull complete
13686b3f2e29: Pull complete
667e8fd02be2: Pull complete
Creating redis_redis_1 ... done
Attaching to redis_redis_1
redis_1  | 1:C 16 Apr 2019 14:57:30.990 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1  | 1:C 16 Apr 2019 14:57:30.992 # Redis version=5.0.2, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1  | 1:C 16 Apr 2019 14:57:30.992 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1  | 1:M 16 Apr 2019 14:57:30.993 * Running mode=standalone, port=6379.
redis_1  | 1:M 16 Apr 2019 14:57:30.993 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1  | 1:M 16 Apr 2019 14:57:30.993 # Server initialized
redis_1  | 1:M 16 Apr 2019 14:57:30.993 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1  | 1:M 16 Apr 2019 14:57:30.994 * Ready to accept connections
redis_1  | 1:M 16 Apr 2019 14:59:16.765 * DB saved on disk
redis_1  | 1:M 16 Apr 2019 14:59:28.481 * DB saved on disk

Redis命令行

AppledeMacBook-Pro:~ apple$ redis-cli -h 127.0.0.1 -p 6381
127.0.0.1:6381> 
127.0.0.1:6381> 
127.0.0.1:6381> keys
(error) ERR wrong number of arguments for 'keys' command
127.0.0.1:6381> keys *
(empty list or set)
127.0.0.1:6381> 
127.0.0.1:6381> 
127.0.0.1:6381> 
127.0.0.1:6381> flushall
OK

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值