问题很简单,水平扩容某个 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 ''
.......
.......
.......
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.