How to run redis on by docker on local mac?

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:

  1. Install Docker on your Mac.
  2. Open a terminal window.
  3. 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
  1. 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.

  1. 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

  1. 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/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章