使用Windows容器在docker桌面上运行Consul并打开实验模式效果很好。但是,如果我尝试将bitnami consul的数据文件挂载到本地卷挂载,则会出现以下错误:chown: cannot access '/bitnami/consul'
我的撰写文件如下所示:
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
如果删除卷部分,则一切正常,但无法持久保存数据。如果遵循readme file中的说明。说到拥有适当的权限,但我不知道如何使用docker桌面使它正常工作。
旁注
如果我不是挂载
/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"
最佳答案
另一个选择是编辑docker-compose.yaml以通过添加user: 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
如果没有
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
但是添加此行后,容器将作为
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
如果容器是作为
root
执行的,则主机卷中的权限应该没有任何问题。关于linux - bitnami领事无法使用docker桌面卷安装访问文件或目录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60933618/