【问题标题】:docker-compose: directory permission errors on bind mountdocker-compose:绑定挂载时的目录权限错误
【发布时间】:2019-01-17 09:36:55
【问题描述】:

尝试使用prometheus 图像启动docker-compose 堆栈(尽管实际服务相当无关紧要。

我创建了以下目录来保存prometheus 数据。

$ ls -ald /prometheus_data/
drwxrwxr-x 3 root root 4096 Jan 17 07:24 /prometheus_data/

并在docker-compose中设置服务如下:

prometheus:
    image: prom/prometheus
    volumes:
        - ./prometheus/:/etc/prometheus/
        - /prometheus_data:/prometheus_data:rw
    command:
        - '--config.file=/etc/prometheus/prometheus.yml'
        - '--storage.tsdb.path=/prometheus_data'
        - '--storage.tsdb.retention=4d'
        - '--web.console.libraries=/usr/share/prometheus/console_libraries'
        - '--web.console.templates=/usr/share/prometheus/consoles'
    ports:
        - 9090:9090
    depends_on:
        - cadvisor
    restart: always

但是服务失败了:

prometheus_1     | level=error ts=2019-01-17T09:35:09.200050622Z caller=main.go:579 err="Opening storage failed open DB in /prometheus_data: open /prometheus_data/146791472: permission denied"
prometheus_1     | level=info ts=2019-01-17T09:35:09.20007784Z caller=main.go:581 msg="See you next time!"

服务不是root用户发起的吗?

为什么会出现上述权限错误?

【问题讨论】:

    标签: docker permissions docker-compose prometheus


    【解决方案1】:

    根据prometheusDockerfileUSER 设置为nobody

    因此,服务无法访问上述目录是有道理的。

    所以问题通过执行解决了

    chgrp -R nogroup /prometheus_data
    

    【讨论】:

    • 对于nobody:nogroup 是否适合使用似乎有些担忧:github.com/prometheus/prometheus/issues/3441。我对此事没有意见,但您可以将容器作为不同的用户/组(例如 1234:5678)执行并将文件系统设置为相同的权限。
    • 您是如何在 docker-compose 文件中发出命令的?
    猜你喜欢
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 2017-05-09
    • 1970-01-01
    • 2020-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多