Refer link: https://blog.csdn.net/weixin_45821811/article/details/116211724
1. docker pull redis
2. docker run with redis config and data file
- create dir
- prepare config file
- redis.conf 文件位置: /home/redis/myredis/redis.conf
- redis 的 data 文件位置 : /home/redis/myredis/data
# can get the file from redis website
3. run
docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 6379:6379 --name myredis -v /home/redis/myredis/myredis.conf:/etc/redis/redis.conf -v /home/redis/myredis/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes --requirepass 000415
--restart=always 总是开机启动
--log 是日志方面的
-p 6379:6379 将 6379 端口挂载出去
--name 给这个容器取一个名字
-v 数据卷挂载 - /home/redis/myredis/myredis.conf:/etc/redis/redis.conf 这里是将 liunx 路径下的 myredis.conf 和 redis 下的 redis.conf 挂载在一起。 - /home/redis/myredis/data:/data 这个同上
-d redis 表示后台启动 redis
redis-server /etc/redis/redis.conf 以配置文件启动 redis,加载容器内的 conf 文件,最终找到的是挂载的目录 /etc/redis/redis.conf 也就是 liunx 下的 /home/redis/myredis/myredis.conf
–appendonly yes 开启 redis 持久化
–requirepass 000415 设置密码 (如果你是通过 docker 容器内部连接的话,就随意,可设可不设。但是如果想向外开放的话,一定要设置)
4. Test
- docker ps -a | grep myredis
- myredis docker ps
- docker logs --since 30m myredis 查看日志
- docker exec -it myredis /bin/bash 进行容器内部连接
myredis docker exec -it myredis redis-cli
127.0.0.1:6379> get s1
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth yourpwd
OK
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "yourpwd"
127.0.0.1:6379>
Simeple way
To run Redis on Docker on your Mac, you can follow these steps:
- Install Docker on your Mac.
- Open a terminal window.
- Run the following command to pull the latest Redis image from Docker Hub:
Code snippet
docker pull redis
Use code with caution. Learn more
content_copy
- Run the following command to create a new Docker container and start the Redis server:
Code snippet
docker run -d -p 6379:6379 redis
# --name give a name for the instance
docker run --name some-redis -d redis
The -d flag tells Docker to run the container in detached mode, so it will not appear in the terminal output. The -p 6379:6379 flag tells Docker to map port 6379 on the Docker host to port 6379 on the Docker container. This will allow you to connect to the Redis server from your Mac using the standard Redis client.
- To verify that the Redis server is running, you can run the following command:
Code snippet
docker ps
This will list all of the Docker containers that are running on your Mac. You should see a line that looks like this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 35213590687c redis "docker-entrypoint.sh …" 5 seconds ago Up 4 seconds 6379/tcp redis
- To connect to the Redis server from your Mac, you can use the Redis client. For example, to list all of the keys in the Redis database, you can run the following command:
Code snippet
redis-cli -h localhost -p 6379
This will connect to the Redis server on your Mac and list all of the keys in the database.
Refer Link:
https://www.docker.com/blog/how-to-use-the-redis-docker-official-image/
文章详细介绍了如何使用Docker来部署和配置Redis服务,包括从DockerHub拉取镜像、创建数据卷、设置配置文件、启动容器、设置持久化和密码保护以及测试连接。此外,还提到了端口映射和日志管理。
314

被折叠的 条评论
为什么被折叠?



