【问题标题】:Docker - chown: changing ownership of '/data/db': Operation not permittedDocker - chown:更改“/data/db”的所有权:不允许操作
【发布时间】:2021-05-12 07:12:17
【问题描述】:

我正在尝试使用 Docker 运行我的应用程序,这是运行 mongo 容器的 yml 文件内容。

 services:
   mongodb:
    image: mongo:3.4
    #    ports:
    #        - "27017:27017"
    volumes:
      - ./data/mongo:/data/db
    restart: always

并在 contianer 中收到此错误:(运行 docker logs 命令后看到此错误)

chown:更改“/data/db”的所有权:不允许操作

主机有 ./data/mongo 文件夹,这里是详细信息。

drwxrwxrwx  2 nfsnobody nfsnobody 4096 May 11 23:13 mongo

我尝试按照其中一个论坛的建议在主机上运行它。

sudo chgrp 1000 ./data/mongo

不确定这将如何帮助解决问题,因为我们得到的错误是在容器文件夹中,而不是来自主机的文件夹,无论如何我都试过了。

但得到了这样的回应:

chgrp:更改“mongo”组:不允许操作

如何解决这个问题?除了“chgrp”还有其他解决方案吗?谢谢。

这是完整的 docker-compose.yml 文件

## You can generate a custom docker compose file automatically on http://reportportal.io/download (Step 2)

## This is example of Docker Compose for ReportPortal
## Do not forget to configure data volumes for production usage

## Execute 'docker-compose -p reportportal up -d --force-recreate'
## to start all containers in daemon mode
## Where:
##      '-p reportportal' -- specifies container's prefix (project name)
##      '-d' -- enables daemon mode
##      '--force-recreate' -- forces re-recreating of all containers

version: '2'

services:

  mongodb:
    image: mongo:3.4
    #    ports:
    #        - "27017:27017"
    volumes:
      - ./data/mongo:/data/db
    restart: always

  registry:
    image: consul:1.0.6
    volumes:
      - ./data/consul:/usr/share/consul/data
#    ports:
#      - "8500:8500"
#      - "8300:8300"
#      - "53:8600/udp"
    command: "agent -server -bootstrap-expect=1 -ui -client 0.0.0.0"
    environment:
      - 'CONSUL_LOCAL_CONFIG={"leave_on_terminate": true}'
    restart: always


  uat:
    image: reportportal/service-authorization:4.2.0
    #ports:
    #  - "9999:9999"
    depends_on:
      - mongodb
    environment:
      - RP_PROFILES=docker
      - RP_SESSION_LIVE=86400 #in seconds
    #      - RP_MONGO_URI=mongodb://localhost:27017
    restart: always

  ### Another option for gateway
  ### Can be used instead of traefik
  #  gateway:
  #    image: fabiolb/fabio:1.5.8-go1.10
  #    ports:
  #      - "9998:9998" # GUI/management
  #      - "8080:9999" # HTTP exposed
  #    environment:
  #      - FABIO_REGISTRY_CONSUL_ADDR=registry:8500
  #      - FABIO_REGISTRY_CONSUL_REGISTER_NAME=gateway
  #      - FABIO_PROXY_ADDR=:9999;rt=300s;wt=300s
  #    restart: always



  gateway:
    image: traefik:1.6.6
    ports:
      - "4444:8080" # HTTP exposed
      - "8081:8081" # HTTP Administration exposed
#    expose:
#      - '8080'
    command:
      - --consulcatalog.endpoint=registry:8500
      - --defaultEntryPoints=http
      - --entryPoints=Name:http Address::8080
      - --web
      - --web.address=:8081
    restart: always

  index:
    image: reportportal/service-index:4.2.0
    environment:
      - RP_SERVER_PORT=8080
      - RP_PROXY_CONSUL=true
    depends_on:
      - registry
      - gateway
    restart: always

  api:
    image: reportportal/service-api:4.3.0
    depends_on:
      - mongodb
    environment:
      - RP_PROFILES=docker
      - JAVA_OPTS=-Xmx1g -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp
    #      - RP_MONGO_URI=mongodb://localhost:27017
    restart: always

  ui:
    image: reportportal/service-ui:4.3.0
    environment:
      - RP_SERVER.PORT=8080
      - RP_CONSUL.TAGS=urlprefix-/ui opts strip=/ui
      - RP_CONSUL.ADDRESS=registry:8500
    restart: always

  analyzer:
    image: reportportal/service-analyzer:4.3.0
    depends_on:
      - registry
      - gateway
      - elasticsearch
    restart: always

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.1.1
    restart: always
    volumes:
      - ./data/elasticsearch:/usr/share/elasticsearch/data
    environment:
      - bootstrap.memory_lock=true
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
  #    ports:
  #        - "9200:9200"

  jira:
    image: reportportal/service-jira:4.0.0
    environment:
      - RP_PROFILES=docker
    #     - RP_MONGO_URI=mongodb://localhost:27017
    restart: always

  rally:
    image: reportportal/service-rally:4.3.0
    environment:
      - RP_PROFILES=docker
    #     - RP_MONGO_URI=mongodb://localhost:27017
    restart: always

【问题讨论】:

  • 您可以使用 '''chmod -R a+rwX directory/''' 向所有用户授予目录的完全权限(如果这对您的环境是安全的)。如果它仍然不起作用,那么分享您的应用程序结构以及整个 docker-compose 和 Dockerfile 内容会很有帮助
  • @Gray_Rhino ,我试过这个但有同样的问题。问题中添加了 yml 文件的全部内容。谢谢你..

标签: mongodb docker docker-volume


【解决方案1】:

如果以 root 身份运行,Mongo 启动脚本会更改 /data/configdb/data/db 中文件的所有权。尝试以nfsnobody(本地./data/mongo的所有者)运行它以跳过该步骤:

  1. id -u nfsnobody获取用户id;
  2. docker-compose.ymlmongodb 下添加user: <id>
services:
  mongodb:
    user: 123 # replace with the value from p1

【讨论】:

  • 这帮助我解决了类似的问题,尽管我需要使用字符串形式的用户名而不是用户 ID
  • @hampercm 两种方式都适用,但有一点区别。如果您使用名称,则容器内必须有一个具有该名称的用户。对于 ID,这不是强制性的。
【解决方案2】:

您似乎开启了用户命名空间重新映射。

在您的主机中打开以下文件

/etc/sysconfig/docker

并添加/修改这些选项,如下所示,如果需要,将 root 替换为您的用户

OPTIONS='--userns-remap=root:root'

【讨论】:

    猜你喜欢
    • 2018-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    相关资源
    最近更新 更多