Docker配置redis

1. 获取redis镜像

  • 获取镜像
$ sudo docker pull redis
  • 查看镜像
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               latest              1e70071f4af4        5 weeks ago         107MB

2. 启动redis容器

# 启动redis容器
$ sudo docker run -p 6379:6379 --name redis-master --restart=always -v /home/yangqian/docker-redis-data/redis-master/data:/data  -d redis redis-server --appendonly yes
# 查看容器进程
$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
7f35465997c4        redis               "docker-entrypoint.s…"   6 seconds ago       Up 5 seconds        0.0.0.0:6379->6379/tcp   redis-master
3dc37943fb7a        mysql               "docker-entrypoint.s…"   2 days ago          Up 29 minutes       0.0.0.0:3307->3306/tcp   mysql-slave1
e37e29f090b7        mysql               "docker-entrypoint.s…"   2 days ago          Up 29 minutes       0.0.0.0:3306->3306/tcp   mysql-master

# 查看redis容器的ip
$ sudo docker inspect 7f |grep 'IPAddress'
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.4",
                    "IPAddress": "172.17.0.4",
# 连接redis容器
$ sudo docker run -it redis redis-cli -h 172.17.0.4
172.17.0.4:6379> set name laowang
OK
172.17.0.4:6379> mset class 01 age 18 gender man
OK
172.17.0.4:6379> keys
(error) ERR wrong number of arguments for 'keys' command
172.17.0.4:6379> keys *
1) "gender"
2) "name"
3) "class"
4) "age"
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页