简体   繁体   English

如何将 mosquitto docker 日志挂载到本地 PC

[英]How to mount mosquitto docker logs to local pc

I have installed eclipse-mosquitto docker image in Ubuntu.我已经在 Ubuntu 中安装了eclipse-mosquitto镜像 I am trying to run it using docker-compose .我正在尝试使用docker-compose运行它。 Mosquitto needs 3 directories as explained in docker hub page: Mosquitto 需要 3 个目录,如 docker hub 页面中所述:

  1. config : which contains mosquitto.conf and bridge.conf files config : 包含 mosquitto.conf 和 bridge.conf 文件
  2. data: which contains mosquitto.db file数据:其中包含 mosquitto.db 文件
  3. log: which contains mosquitto.log file日志:其中包含 mosquitto.log 文件

In my local PC I have created a directory named mosquitto which has all the above directory and files:在我的本地 PC 中,我创建了一个名为mosquitto的目录,其中包含上述所有目录和文件:

mosquitto

    -> config
        -> mosquitto.conf
        -> conf.d
            -> bridge.conf 
    -> data
        -> mosquitto.db
    -> log
        -> mosquitto.log

Below is the docker-compose.yml file:下面是 docker-compose.yml 文件:

version: '2.4'

services:
    mosquitto:
        image: eclipse-mosquitto:latest
        volumes:
            - /home/john/Documents/docker/mosquitto:/mosquitto
        restart: always

and I am starting it as sudo docker-compose up .我将它作为sudo docker-compose up Its container starts to run fine and I can see all the directories and files properly mounted inside the mosquitto container.它的容器开始运行良好,我可以看到所有目录和文件都正确安装在 mosquitto 容器内。 I can see the logs starts to come and mosquitto.log file size is also increasing inside the container but there is no log present in my local pc.我可以看到日志开始出现,并且容器内的mosquitto.log文件大小也在增加,但我的本地电脑中没有日志。

Why is this happening when I have mounted the volume.为什么在我安装卷后会发生这种情况。 I want to also get the logs in the mosquitto.log in ubuntu local pc.我还想在 ubuntu 本地 pc 中获取mosquitto.log中的日志。 How can I do this.我怎样才能做到这一点。 Can anyone please suggest some good solution.任何人都可以请提出一些好的解决方案。 Thanks谢谢

This is because docker is creating 2 local volumes and mounting them on top of the /mosquitto directory to hold the persistence and log data.这是因为 docker 正在创建 2 个本地卷并将它们安装在/mosquitto目录的顶部以保存持久性和日志数据。

Add the extra mounts to the volumes section and it will then bind the local directories rather than create unnamed local volumes.将额外的挂载添加到卷部分,然后它将绑定本地目录而不是创建未命名的本地卷。

version: '2.4'

services:
    mosquitto:
        image: eclipse-mosquitto:latest
        volumes:
            - /home/john/Documents/docker/mosquitto:/mosquitto
            - /home/john/Documents/docker/mosquitto/data:/mosquitto/data
            - /home/john/Documents/docker/mosquitto/log:/mosquitto/log
        restart: always

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM