docker-compose:绑定安装上的目录权限错误 [英] docker-compose: directory permission errors on bind mount

查看:158
本文介绍了docker-compose:绑定安装上的目录权限错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Trying to spin up a docker-compose stack with a prometheus image (although the actual service is rather irrelevant.

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

I have created the following dir to persist prometheus data.

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

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

and set up the service in docker-compose as follows:

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 用户启动的服务吗?

Isn't the service initiated by the root user?

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

Why its gets the above permission errors?

推荐答案

根据 prometheus Dockerfile USER 设置为 nobody .

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

So it makes sense that the above dir is not accessible by the service.

因此,通过执行以下操作解决了该问题

So the problem was solved by performing a

chgrp -R nogroup /prometheus_data

这篇关于docker-compose:绑定安装上的目录权限错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆