version: '3.1'
services:
my-service:
image: my-image:latest
deploy:
replicas: 3
update_config:
parallelism: 1
delay: 10s
order: start-first
volumes:
- type: volume
source: my-service-data
target: /app/data
logging:
driver: json-file
options:
max-size: 10m
max-file: 5
volumes:
my-service-data:
driver: local
driver_opts:
type: nfs
o: addr=192.168.1.1,nfsvers=4
device: ":/data/my-service"
上述解决方案使用Docker Compose配置文件中的logging部分实现了保留Docker注册表中最后5个镜像的功能。其中,max-size指定了每个日志文件最大为10M,max-file指定了最多保留5个文件。您可以根据需要更改这些值。