简体   繁体   English

bitnami consul 无法使用 docker 桌面卷挂载访问文件或目录

[英]bitnami consul cannot access file or directory using docker desktop volume mount

Running Consul with docker desktop using windows containers and experimental mode turned on works well.使用 Windows 容器和实验模式在 docker 桌面上运行 Consul 效果很好。 However if I try mounting bitnami consul's datafile to a local volume mount I get the following error:但是,如果我尝试将 bitnami consul 的数据文件挂载到本地卷挂载,则会出现以下错误:

chown: cannot access '/bitnami/consul'

powershell chown 错误

My compose file looks like this:我的撰写文件如下所示:

version: "3.7"
services:
  consul:
    image: bitnami/consul:latest
    volumes:
      - ${USERPROFILE}\DockerVolumes\consul:/bitnami
    ports:
      - '8300:8300'
      - '8301:8301'
      - '8301:8301/udp'
      - '8500:8500'
      - '8600:8600'
      - '8600:8600/udp'
    networks: 
      nat:        
        aliases:
          - consul

If I remove the volumes part, everything works just fine, but I cannot persist my data.如果我删除卷部分,一切正常,但我无法保留我的数据。 If followed instructions in the readme file .如果遵循自述文件中的说明 The speak of having the proper permissions, but I do not know how to get that to work using docker desktop.谈到拥有适当的权限,但我不知道如何使用 docker desktop 让它工作。

Side note If I do not mount /bitnami but /bitnami/consul , I get the following error: 2020-03-30T14:59:00.327Z [ERROR] agent: Error starting agent: error="Failed to start Consul server: Failed to start Raft: invalid argument"旁注如果我不挂载/bitnami而是/bitnami/consul ,我会收到以下错误: 2020-03-30T14:59:00.327Z [ERROR] agent: Error starting agent: error="Failed to start Consul server: Failed to start Raft: invalid argument" powershell 无法启动 Raft

Another option is to edit the docker-compose.yaml to deploy the consul container as root by adding the user: root directive:另一种选择是编辑 docker-compose.yaml 以通过添加user: root指令以 root 身份部署 consul 容器:

version: "3.7"
services:
  consul:
    image: bitnami/consul:latest
    user: root
    volumes:
      - ${USERPROFILE}\DockerVolumes\consul:/bitnami
    ports:
      - '8300:8300'
      - '8301:8301'
      - '8301:8301/udp'
      - '8500:8500'
      - '8600:8600'
      - '8600:8600/udp'
    networks: 
      nat:        
        aliases:
          - consul

Without user: root the container is executed as non-root (user 1001):没有user: root容器以非 root 用户身份执行(用户 1001):

▶ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                                                                                              NAMES
0c590d7df611        bitnami/consul:1    "/opt/bitnami/script…"   4 seconds ago       Up 3 seconds        0.0.0.0:8300-8301->8300-8301/tcp, 0.0.0.0:8500->8500/tcp, 0.0.0.0:8301->8301/udp, 0.0.0.0:8600->8600/tcp, 0.0.0.0:8600->8600/udp   bitnami-docker-consul_consul_1

▶ dcexec 0c590d7df611
I have no name!@0c590d7df611:/$ whoami
whoami: cannot find name for user ID 1001

But adding this line the container is executed as root :但是添加这一行,容器以root身份执行:

▶ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                                                                                              NAMES
ac206b56f57b        bitnami/consul:1    "/opt/bitnami/script…"   5 seconds ago       Up 4 seconds        0.0.0.0:8300-8301->8300-8301/tcp, 0.0.0.0:8500->8500/tcp, 0.0.0.0:8301->8301/udp, 0.0.0.0:8600->8600/tcp, 0.0.0.0:8600->8600/udp   bitnami-docker-consul_consul_1

▶ dcexec ac206b56f57b
root@ac206b56f57b:/# whoami
root

If the container is executed as root there shouldn't be any issue with the permissions in the host volume.如果容器以root身份执行,则主机卷中的权限应该没有任何问题。

Consul container is a non-root container , in those cases, the non-root user should be able to write in the volume. Consul 容器是一个非 root 容器,在这种情况下,非 root 用户应该能够在卷中写入。

Using host directories as a volume you need to ensure that the directory you are mounting into the container has the proper permissions, in that case, writable permission for others .使用主机目录作为卷,您需要确保安装到容器中的目录具有适当的权限,在这种情况下, others可写权限。 You can modify the permission by running sudo chmod o+x ${USERPROFILE}\\DockerVolumes\\consul (or the correct path to the host directory).您可以通过运行sudo chmod o+x ${USERPROFILE}\\DockerVolumes\\consul (或主机目录的正确路径)来修改权限。

This local folder is created the first time you run docker-compose up or you can create it by yourself with mkdir .这个本地文件夹是在您第一次运行docker-compose up时创建的,或者您可以使用mkdir自己创建它。 Once created (manually or automatically) you should give the proper permissions with chmod .创建(手动或自动)后,您应该使用chmod授予适当的权限。

I am not familiar with Docker desktop nor Windows environments, but you should be able to do the equivalent actions using a CLI.我不熟悉 Docker 桌面或 Windows 环境,但您应该能够使用 CLI 执行等效操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM