Docker
/etc/prometheus/prometheus.yml 的權限被拒絕;無法部署 prom/prometheus 容器
我正在使用 NFS 掛載
/etc/prometheus/prometheus.yml
通過 Ansible 向 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 部署容器時問題是相同的,而沒有遠端文件系統安裝到 at 的劇本
/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
容器中的問題嗎?**編輯:**我通過為 docker 提供與容器共享的本地目錄而不是 NFS 掛載來進行測試。這已成功與容器共享,並且容器已啟動。指向 NFS 問題,但我還沒有弄清楚。