V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
tqccc
V2EX  ›  问与答

问问大佬们一个 docker-compose 水平扩展容器挂载目录的问题

  •  
  •   tqccc · 2020-05-15 15:17:12 +08:00 · 1124 次点击
    这是一个创建于 1432 天前的主题,其中的信息可能已经有所发展或是发生改变。

    问题很简单,水平扩容某个 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 ''
    .......
    .......
    .......
    
    
    4 条回复    2020-05-19 19:21:05 +08:00
    robot1
        1
    robot1  
       2020-05-15 15:44:33 +08:00   ❤️ 1
    想平滑扩展 就上日志收集
    可以在启动的时候获取机器名,日志名加上机器名,但你都分布式了不用日志收集,这种分散的日志很难查问题
    tqccc
        2
    tqccc  
    OP
       2020-05-15 16:15:05 +08:00
    @robot1 噢噢懂了,多谢大佬,按照你的提示搜到不少知识,以及发现每个容器的标准输出日志都在
    /var/lib/docker/containers/ 里头
    robot1
        3
    robot1  
       2020-05-15 23:06:11 +08:00   ❤️ 1
    @tqccc 互相学习
    tqccc
        4
    tqccc  
    OP
       2020-05-19 19:21:05 +08:00 via Android
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   962 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:33 · PVG 05:33 · LAX 14:33 · JFK 17:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.