问题很简单,水平扩容某个 service 后,因为 docker-compose.yml 文件里声明的宿主机挂载目录就一个,比如我挂载出日志文件,扩容 --scale myService=2
, 启动以后发现宿主机只有一个 logs,而且里边日志文件内容每行都输出了 2 次,有什么好办法自动区分挂载目录或者文件吗?
这是我的 docker-compose.yml:
version: '3'
services:
nginx:
image: nginx:latest
volumes:
- /data/nginx/nginx.conf:/etc/nginx/nginx.conf
depends_on:
- myService
ports:
- "80:80"
myService:
build:
context: ./
restart: always
image: tqc/myService
volumes:
- /data/myService/logs:/myService/logs
extra_hosts:
- "redisHost:192.168.99.1"
- "mysqlHost:192.168.99.1"
启动命令:
docker-compose -f docker-compose.yml build --no-cache
docker-compose -f docker-compose.yml up -d --scale myService=2
宿主机挂载目录 /data/myService/logs 里头的日志重复现象(输出了两次。。。。):
......
......
......
......
2020-05-15 15:09:34.399 INFO 10520 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper 163 : Found 1 custom documentation plugin(s)
2020-05-15 15:09:34.399 INFO 10520 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper 163 : Found 1 custom documentation plugin(s)
2020-05-15 15:09:34.471 INFO 10520 --- [ main] s.d.s.w.s.ApiListingReferenceScanner 41 : Scanning for api listing references
2020-05-15 15:09:34.471 INFO 10520 --- [ main] s.d.s.w.s.ApiListingReferenceScanner 41 : Scanning for api listing references
2020-05-15 15:09:34.773 INFO 10520 --- [ main] o.a.coyote.http11.Http11NioProtocol 173 : Starting ProtocolHandler ["http-nio-6060"]
2020-05-15 15:09:34.773 INFO 10520 --- [ main] o.a.coyote.http11.Http11NioProtocol 173 : Starting ProtocolHandler ["http-nio-6060"]
2020-05-15 15:09:34.806 INFO 10520 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer 204 : Tomcat started on port(s): 6060 ( http) with context path ''
2020-05-15 15:09:34.806 INFO 10520 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer 204 : Tomcat started on port(s): 6060 ( http) with context path ''
.......
.......
.......
1
robot1 2020-05-15 15:44:33 +08:00 1
想平滑扩展 就上日志收集
可以在启动的时候获取机器名,日志名加上机器名,但你都分布式了不用日志收集,这种分散的日志很难查问题 |
2
tqccc OP @robot1 噢噢懂了,多谢大佬,按照你的提示搜到不少知识,以及发现每个容器的标准输出日志都在
/var/lib/docker/containers/ 里头 |
4
tqccc OP |