docker-compose 是什么
熟悉docker的人都知道Dockerfile用來(lái)構(gòu)件單個(gè)鏡像服務(wù)的偏窝,想要運(yùn)行服務(wù)校焦,要輸入復(fù)雜的 run 命令來(lái)啟動(dòng)并配置服務(wù)运吓。
對(duì)于服務(wù)間依賴以及服務(wù)的環(huán)境變量跌穗、網(wǎng)絡(luò)參數(shù)佃声、文件掛載等操作偷霉,當(dāng)然可以使用yaml文件來(lái)配置迄委,這就是docker-compose
docker-compose 就是Docker編排工具,可以優(yōu)雅的配置服務(wù)間的依賴關(guān)系腾它,服務(wù)的屬性控制跑筝,減少運(yùn)維成本。
docker-compose 安裝 redis單節(jié)點(diǎn)
目錄結(jié)構(gòu)
redis
├─ docker-compose.yml
└─ redis.conf
- ./redis.conf redis單節(jié)點(diǎn)服務(wù)配置文件
- ./docker-compose.yml docker-compose配置文件
redis單節(jié)點(diǎn) docker-compose.yml 文件
version: '3'
services:
redis:
image: redis:latest
restart: "no"
container_name: redis
ports:
- "5070:6379"
volumes:
- ./redis.conf:/etc/redis/redis.conf
- ./data:/data
command: redis-server /etc/redis/redis.conf
privileged: true
- image 服務(wù)使用的鏡像
- restart: always/no 保持無(wú)服務(wù)開(kāi)機(jī)啟動(dòng)或者其他情況下正常啟動(dòng)/不自動(dòng)啟動(dòng)
- volumes 掛載外部路徑到容器內(nèi)部
- ports 暴露服務(wù)內(nèi)部端口
- ./docker-compose.yml docker-compose配置文件
服務(wù)配置文件redis.conf
bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
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
replica-serve-stale-data yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
oom-score-adj no
oom-score-adj-values 0 200 800
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
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-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-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
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
啟動(dòng)服務(wù)
執(zhí)行命令啟動(dòng)服務(wù) docker-compose up -d
等待success提示則=啟動(dòng)成功
服務(wù)啟動(dòng)成功瞒滴,就可以使用訪問(wèn)redis單節(jié)點(diǎn)服務(wù)了
docker-compose 常用命令
屬性 | 描述 |
---|---|
docker-compose build | (構(gòu)建yml中某個(gè)服務(wù)的鏡像) |
docker-compose ps | (查看已經(jīng)啟動(dòng)的服務(wù)狀態(tài)) |
docker-compose kill | (停止某個(gè)服務(wù)) |
docker-compose logs | (可以查看某個(gè)服務(wù)的log) |
docker-compose port | (打印綁定的public port) |
docker-compose pull | (pull服務(wù)鏡像) |
docker-compose up | (啟動(dòng)yml定義的所有服務(wù)) |
docker-compose stop | (停止yml中定義的所有服務(wù)) |
docker-compose start | (啟動(dòng)被停止的yml中的所有服務(wù)) |
docker-compose kill | (強(qiáng)行停止yml中定義的所有服務(wù)) |
docker-compose rm | (刪除yml中定義的所有服務(wù)) |
docker-compose restart | (重啟yml中定義的所有服務(wù)) |
docker-compose scale | (擴(kuò)展某個(gè)服務(wù)的個(gè)數(shù)曲梗,可以向上或向下) |
docker-compose version | (查看compose的版本) |
更多好玩好看的內(nèi)容,歡迎到我的博客交流妓忍,共同進(jìn)步????????WaterMin