docker安装并运行redis

  拉取镜像:

[mall@VM_0_7_centos ~]$ sudo docker pull redis:3.2
[sudo] password for mall: 
3.2: Pulling from library/redis
f17d81b4b692: Pull complete 
b32474098757: Pull complete 
8980cabe8bc2: Pull complete 
58af19693e78: Pull complete 
a977782cf22d: Pull complete 
9c1e268980b7: Pull complete 
Digest: sha256:7b0a40301bc1567205e6461c5bf94c38e1e1ad0169709e49132cafc47f6b51f3
Status: Downloaded newer image for redis:3.2
docker.io/library/redis:3.2

  创建本地数据目录,docker运行redis:

[mall@VM_0_7_centos ~]$ mkdir -p mydata/redis/data

[mall@VM_0_7_centos ~]$ sudo docker run -p 6379:6379 --name redis -v /mydata/redis/data:/data -d redis:3.2 redis-server --appendonly yes
55a9d1906429869ab46db6e889c44b5822f695ec81869f1cfc8f9ed0ddb48ee8

  参数说明:

  -p 6379:6379:端口映射,本地端口6379映射到docker容器端口6379

  --name redis:指定容器名称为redis

  -v /mydata/redis/data:/data:将容器的配置文件夹/data挂在到当前主机/mydata/redis/data

  -d -d redis:3.2 redis-server:以守护进程deamon运行redis服务器

  --appendonly yes:开启AOF模式持久化

  进入docker,使用redis客户端连接服务端:

[mall@VM_0_7_centos ~]$ sudo docker exec -it redis redis-cli
[sudo] password for mall: 
127.0.0.1:6379> set hello world
OK
127.0.0.1:6379> get hello
"world"
127.0.0.1:6379> 

猜你喜欢

转载自www.cnblogs.com/wuxun1997/p/11769867.html