我使用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挂载来进行测试。这已成功地与容器共享,并启动了容器。指出NFS的问题,但我还没有弄清楚。
https://unix.stackexchange.com/questions/616911
复制相似问题