/etc/prometheus/prometheus.yml 上的权限被拒绝;无法部署 prom/prometheus

Permission denied on /etc/prometheus/prometheus.yml; cannot deploy prom/prometheus

我正在使用 NFS 挂载通过 Ansible 将 /etc/prometheus/prometheus.yml(默认)配置文件提供给 prom/prometheus docker 图像。部署容器时,我在容器日志中收到以下错误,容器在几秒钟后重新启动。

level=error ts=2020-10-28T16:01:04.432Z caller=main.go:290 msg="Error loading config (--config.file=/etc/prometheus/prometheus.yml)" err="open /etc/prometheus/prometheus.yml: permission denied"

我可以在我的 docker 主机(一个 Raspberry Pi 4)上浏览安装的文件系统,触摸文件并以启动容器的用户身份读取 prometheus.yml

以下是我的剧本中的相关任务,从 CLI 部署容器时的问题是相同的,而没有将远程文件系统安装到 [=16] 的剧本=],并在 /etc/prometheus

处作为体积传递给容器

docker run -p 9090:9090 -v /mnt/prometheus:/etc/prometheus prom/prometheus

prometheus/tasks/main.ymlbecome: yes在调用这个角色的playbook中设置)

  - name: "Create mountpoint"
    file: 
        path: "{{ prometheus_mount_path }}"
        state: directory
        mode: 0777
        owner: root
        group: users
        

  - name: "Mount nfs drive for prometheus filesystem"
    mount: 
        path: "{{ prometheus_mount_path }}"
        src: "{{ nfs_server }}:{{ prometheus_nfs_path }}"
        state: mounted
        fstype: nfs
        
  - name: "Create prometheus.yml in mountpoint from template"
    template: 
        src: prometheus.yml.j2
        dest: "{{ prometheus_mount_path }}/prometheus.yml"

        
  - name: "Deploy prometheus container"
    docker_container:
        name: prometheus
        image: prom/prometheus:latest
        restart_policy: always
        state: started
        network_mode: host
        hostname: prometheus
#        exposed_ports: 9090
        published_ports: 9090:9090
        user: 995:1002
        mounts: 
        volumes:
            - "{{ prometheus_mount_path }}:/etc/prometheus"
        comparisons:
            '*': ignore
            env: strict

知道什么会导致或如何解决容器中的 permission denied 问题吗?

更新: 我通过与容器共享 docker 主机上的目录进行测试。已成功分享。指向 NFS 问题,但我正在努力解决这个问题。

我有一个类似的问题,虽然不是 NFS,而是挂载一个简单的目录。对我来说,这个问题的答案修复了它:.

显然 Prometheus Docker 正在使用用户 nobody,将文件夹权限设置为 nogroup 对我有用:

chgrp -R nogroup /mnt/prometheus

因此在您的 Ansible 剧本中:

- name: fix permissions for prometheus mnt folder
  file:
    path: '/mnt/prometheus'
    group: nogroup
    recurse: yes
  become: yes

在我的特殊情况下,我发现问题出在 NFS 压缩功能上。我的 NFS 导出器 - 较旧的 Synology NAS - 不允许我完全禁用压缩。如果有,@nehtor.t 的回答可能会有帮助。相反,我不得不使用 NFS GUI 中的“将所有用户映射到管理员”设置,这允许连接 NFS 共享上的适当权限以适当 chown.