这里对 docker run -it --link test-redis:redis --rm redis redis-cli -h redis -p 6379
进行一下解析
Option | Comment |
---|---|
docker run | 调用 docker 命令的 run 子命令 |
-i | 打开 STDIN ,进入交互模式 |
-t | 分配一个伪终端,一般都和 -i 一起使用 |
--link test-redis:redis | 连接 test-redis 容器,并且为这个容器定义一个别名,叫 redis (redis-cli -h redis -p 6379 中指定的 redis 就是用的这个别名) |
--rm | 此容器用完就删掉,不留存,一般用在短期前台交互的情况下(默认特性是不删的) |
这里稍微就 -p、-P、--link、--expose、EXPOSE
进行一下区分
Item | Comment |
---|---|
EXPOSE | 记录服务可用的端口,但是并不创建和宿主机之间的映射,只出现在Dockerfile中 |
--expose | 运行时暴露端口,但是并不创建和主机之间的映射,同 EXPOSE 功能一样,但只出现在 CLI 中 |
-p | 创建端口映射规则,如-p ip:hostPort:containerPort, 必须指定 containerPort ,如果没有指定 hostPort, Docker会自动分配端口 |
-P | 将Dockerfile 里暴露的所有容器端口映射到动态分配的宿主机端口上 |
--link | 在容器之间创建链接,如 --link name:alias,这会创建一系列环境变量,并在消费者容器的 /etc/hosts 文件里添加入口项,必须暴露或发布端口 |
操作和正常使用客户端一样
[root@h104 ~]# docker run -it --link test-redis:redis --rm redis redis-cli -h redis -p 6379
redis:6379> get a
(nil)
redis:6379> set a b
OK
redis:6379> get a
"b"
redis:6379>
指定配置后,映射本地卷,就可以对数据文件和日志文件的读写位置进行控制
[root@h104 x]# vim redis6379.conf
[root@h104 x]# cat redis6379.conf
daemonize no
pidfile /data/redis6379.pid
port 6379
tcp-backlog 511
timeout 1800
tcp-keepalive 0
loglevel notice
logfile "/data/redis6379.log"
databases 50
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump6379.rdb
dir /data/
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly6379.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
[root@h104 x]#
[root@h104 x]# diff /tmp/redis.conf ./redis6379.conf
1,2c1,2
< daemonize yes
< pidfile /var/run/redis.pid
---
> daemonize no
> pidfile /data/redis6379.pid
5c5
< timeout 0
---
> timeout 1800
8,9c8,9
< logfile ""
< databases 20
---
> logfile "/data/redis6379.log"
> databases 50
16,17c16,17
< dbfilename dump.rdb
< dir ./
---
> dbfilename dump6379.rdb
> dir /data/
25c25
< appendfilename "appendonly.aof"
---
> appendfilename "appendonly6379.aof"
[root@h104 x]#
后面是与默认配置的差异,这里稍微解释一
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。