Docker安装Redis

1,368 阅读3分钟

安装

# docker pull redis


Using default tag: latest
latest: Pulling from library/redis
6ec7b7d162b2: Already exists 
1f81a70aa4c8: Pull complete 
968aa38ff012: Pull complete 
884c313d5b0b: Pull complete 
6e858785fea5: Pull complete 
78bcc34f027b: Pull complete 
Digest: sha256:0f724af268d0d3f5fb1d6b33fc22127ba5cbca2d58523b286ed3122db0dc5381
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest

查看

# docker images

REPOSITORY                       TAG       IMAGE ID       CREATED        SIZE
portainer/portainer-ce           latest    980323c8eb3f   27 hours ago   196MB
mysql                            5.7.32    f07dfa83b528   2 weeks ago    448MB
redis                            latest    ef47f3b6dc11   3 weeks ago    104MB
deepdiver/docker-oracle-xe-11g   latest    396b3e06a5dc   5 years ago    2.7GB

运行

# docker run -itd -p 6379:6379 --name redis6 redis --requirepass '123456'

e2daf821c5ef2cd0519e1607be71741d789417a737b3f873d43591150a7f8552

-i:以交互模式运行容器,通常与 -t 同时使用

-t:为容器重新分配一个伪输入终端,通常与 -i 同时使用

-d:后台运行容器,并返回容器ID

-p:指定端口映射,格式为:主机(宿主)端口:容器端口

-name:为容器指定一个名称:redis6

redis:镜像名

--requirepass:配置密码(123456)

查看运行的Redis容器

# docker ps

CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                    NAMES
e2daf821c5ef   redis     "docker-entrypoint.s…"   4 minutes ago   Up 4 minutes   0.0.0.0:6379->6379/tcp   redis6

查看日志

# docker logs redis6
1:C 08 Jan 2021 09:18:47.741 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 08 Jan 2021 09:18:47.742 # Redis version=6.0.9, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 08 Jan 2021 09:18:47.742 # Configuration loaded
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 6.0.9 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

1:M 08 Jan 2021 09:18:47.745 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 08 Jan 2021 09:18:47.745 # Server initialized
1:M 08 Jan 2021 09:18:47.745 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:M 08 Jan 2021 09:18:47.745 # 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 madvise > /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 (set to 'madvise' or 'never').
1:M 08 Jan 2021 09:18:47.746 * Ready to accept connections

登陆Redis-Client

# docker exec -it redis6 /bin/bash
root@e2daf821c5ef:/data# 


root@e2daf821c5ef:/data# redis-cli
127.0.0.1:6379> 

# 输入密码123456
127.0.0.1:6379> auth 123456
OK