FROM alpine:latest MAINTAINER hz7726@163.com RUN apk add --no-cache --virtual .build-deps curl gcc supervisor linux-headers make musl-dev tar \ && mkdir /data \ && cd /data \ && curl -sO http://download.redis.io/releases/redis-4.0.11.tar.gz \ && tar xf redis-4.0.11.tar.gz \ && rm -fr redis-4.0.11.tar.gz \ && rm -fr /var/cache/apk/* \ && cd redis-4.0.11 \ && make PREFIX=/usr/local/redis install \ && rm -fr redis-4.0.11 COPY ./supervisord.conf /etc/supervisord.conf COPY ./startredis.sh /startredis.sh EXPOSE 6379/tcp RUN chmod +x /startredis.sh ONBUILD RUN /usr/bin/supervisorctl reload EnTRYPOINT ["/startredis.sh"] ###nTR 是這個博客的違禁詞語 我就小寫了 #CMD ["/usr/local/redis/bin/redis-server","/etc/redis/redis.conf"]
bind 0.0.0.0 protected-mode yes port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize no supervised no pidfile /var/run/redis/redis.pid loglevel notice logfile /data/redis/redis.log 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 dir /data/redis/ 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 maxmemory 495000000 lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no slave-lazy-flush no 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 no 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 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
[unix_http_server] file=/run/supervisord.sock ; (the path to the socket file) [supervisord] logfile=/var/log/supervisord.log ; (main log file;default $CWD/supervisord.log) loglevel=info ; (log level;default info; others: debug,warn,trace) [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///run/supervisord.sock ; use a unix:// URL for a unix socket [program:redis-4.0.11] command=/bin/sh -c "exec /usr/local/redis/bin/redis-server /etc/redis/redis.conf" autostart=true autorestart=true startretries=3 startsecs=10 stdout_events_enabled=true stderr_events_enabled=true stderr_logfile_maxbytes=20MB stdout_logfile_backups = 5
[program:redis-4.0.11] command=/bin/sh -c "exec /usr/local/redis/bin/redis-server /etc/redis/redis.conf" ; 程序啓動命令 autostart=true ; 在supervisord啓動的時候也自動啓動 startsecs=10 ; 啓動10秒後沒有異常退出,就表示進程正常啓動了,默認爲1秒 autorestart=true ; 程序退出後自動重啓,可選值:[unexpected,true,false],默認爲unexpected,表示進程意外殺死後才重啓 startretries=3 ; 啓動失敗自動重試次數,默認是3 user=tomcat ; 用哪一個用戶啓動進程,默認是root priority=999 ; 進程啓動優先級,默認999,值小的優先啓動 redirect_stderr=true ; 把stderr重定向到stdout,默認false stdout_logfile_maxbytes=20MB ; stdout 日誌文件大小,默認50MB stdout_logfile_backups = 20 ; stdout 日誌文件備份數,默認是10 ; stdout 日誌文件,須要注意當指定目錄不存在時沒法正常啓動,因此須要手動建立目錄(supervisord 會自動建立日誌文件) stdout_logfile=/opt/apache-tomcat-8.0.35/logs/catalina.out stopasgroup=false ;默認爲false,進程被殺死時,是否向這個進程組發送stop信號,包 括子進程 killasgroup=false ;默認爲false,向進程組發送kill信號,包括子進程
#!/bin/sh nohup supervisord -n -c /etc/supervisord.conf &
docker build -t fangxin:redis4.0.11 .
docker run -itd -p 6399:6379 -v /etc/redis.conf:/etc/redis/redis.conf:rw -v /mnt/redis:/data/redis:rw -v /data/soft/redis/startredis.sh:/startredis.sh:rw --name redis4_0_11 fangxin3-redis:4.0.11
root@mysql-2:/data/soft/redis# cat docker-compose.yaml version: "3" services: redis: image: fangxin:redis4.0.11 restart: always container_name: test-redis4.0.11 hostname: redis4.0.11 sysctls: net.core.somaxconn: '1024' #fs.file-max: '100000' volumes: - "/etc/localtime:/etc/localtime:ro" - "/etc/redis.conf:/etc/redis/redis.conf:rw" - "/mnt/redis:/data/redis:rw" - "/data/soft/redis/startredis.sh:/startredis.sh:rw" - "/data/soft/redis/supervisord.conf:/etc/supervisord.conf:rw" dns: - "8.8.8.8" ports: - "6400:6379" ulimits: nproc: 65535 nofile: soft: 20000 hard: 40000 deploy: resources: limits: cpus: "0.30" memory: "512M" healthcheck: test: ["CMD","nc -v -w 5 localhost -z 6379||exit 1"] interval: 60s timeout: 10s retries: 3
docker-compose up -dnode