1:Docker拉取鏡像
指令::docker pull <鏡像名稱>:<版本号>
docker pull redis
三、Docker挂載配置檔案
接下來就是要将redis 的配置檔案進行挂載,以配置檔案方式啟動redis 容器。(挂載:即将宿主的檔案和容器内部目錄相關聯,互相綁定,在主控端内修改檔案的話也随之修改容器内部檔案)
1)、挂載 redis 的配置檔案
2)、挂載 redis 的持久化檔案(為了資料的持久化)。
本人的配置檔案是放在
liunx 下redis.conf檔案位置: /home/redis/redis.conf
liunx 下redis的data檔案位置 : /home/redis/data
mkdir -p /home/redis/ 指令 是不存在就直接建立/home/redis/檔案夾
myredis.conf 是我手動建立的。 (檔案在文末,redis.conf 的标準檔案在redis官網也可以找到)
四、啟動redis容器
docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 6379:6379 --name myredis -v /home/redis/myredis.conf:/etc/redis/redis.conf -v /home/redis/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.conf:/etc/redis/redis.conf 這裡是将 liunx 路徑下的myredis.conf 和redis下的redis.conf 挂載在一起。
- /home/redis/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 容器内部連接配接的話,就随意,可設可不設。但是如果想向外開放的話,一定要設定)
五、測試
1、通過docker ps指令檢視啟動狀态
docker ps -a |grep myredis # 通過docker ps指令檢視啟動狀态,是否成功.
2、檢視容器運作日志
指令:docker logs --since 30m <容器名>
此處 --since 30m 是檢視此容器30分鐘之内的日志情況。
docker logs --since 30m myredis
六、配置檔案
myredis.conf
# bind 192.168.1.100 10.0.0.1 # bind 127.0.0.1 ::1 #bind 127.0.0.1 protected-mode no port 6379 tcp-backlog 511 requirepass 000415 timeout 0 tcp-keepalive 300 daemonize no supervised no pidfile /var/run/redis_6379.pid loglevel notice logfile "" databases 30 always-show-logo yes save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump.rdb dir ./ replica-serve-stale-data yes replica-read-only yes repl-diskless-sync no repl-disable-tcp-nodelay no replica-priority 100 lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no replica-lazy-flush no appendonly yes appendfilename "appendonly.aof" no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes aof-use-rdb-preamble yes lua-time-limit 5000 slowlog-max-len 128 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-size -2 list-compress-depth 0 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 stream-node-max-bytes 4096 stream-node-max-entries 100 activerehashing yes hz 10 dynamic-hz yes aof-rewrite-incremental-fsync yes rdb-save-incremental-fsync yes |