我使用NFS挂载将/etc/prometheus/prometheus.yml (默认)配置文件提供给prom/prometheus映像,所有这些都是通过Ansible提供的。部署容器时,我在容器日志中得到以下错误,几秒钟后容器重新启动。
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"
我可以在我的停靠主机( Raspberry 4)上浏览挂载的文件系统,触摸文件,并以启动容器的用户身份读取prometheus.yml。
下面是我的剧本中的相关任务,当从CLI部署容器时,问题是相同的,而不使用安装在/mnt/prometheus上的远程文件系统,并在/etc/prometheus作为卷传递给容器时,问题是相同的。
docker run -p 9090:9090 -v /mnt/prometheus:/etc/prometheus prom/prometheus
prometheus/tasks/main.yml (become: yes设置在调用此角色的剧本中)
- 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问题吗?
更新:通过与容器共享停靠主机上的目录来测试。成功地分享了这一点。指出了NFS的问题,但我很难弄清楚。
发布于 2020-11-10 15:56:54
在我的具体案例中,我发现这个问题是NFS压缩的一个功能。我的NFS出口商--一种较旧的语法NAS --不允许我完全禁用壁球。如果是这样的话,@nehtor.t的回答可能会有所帮助。相反,我必须使用NFS中的“映射所有用户到管理”设置,这允许将NFS共享的适当权限连接到适当的chown。
发布于 2020-11-10 13:47:38
我也有类似的问题,虽然不是NFS,而是安装一个简单的目录。对我来说,这个问题的答案是固定的:docker-compose: directory permission errors on bind mount。
显然,Prometheus正在使用用户nobody,将文件夹权限设置为nogroup适用于我:
chgrp -R nogroup /mnt/prometheus所以在你的游戏手册里:
- name: fix permissions for prometheus mnt folder
file:
path: '/mnt/prometheus'
group: nogroup
recurse: yes
become: yeshttps://stackoverflow.com/questions/64578730
复制相似问题