问题描述
我的 docker-compose.yml
:
solr:
image: solr:8.6.2
container_name: myproject-solr
ports:
- "8983:8983"
volumes:
- ./data/solr:/var/solr/data
networks:
static-network:
ipv4_address: 172.20.1.42
用 docker-compose up -d --build
启动Docker之后, solr容器关闭,日志( docker日志myproject-solr
)显示如下:
After bringing up the docker with docker-compose up -d --build
, the solr container is down and the log (docker logs myproject-solr
) shows this:
Copying solr.xml
cp: cannot create regular file '/var/solr/data/solr.xml': Permission denied
我注意到,如果我将计算机上的全部权限授予数据目录 sudo chmod 777 ./data/solr/ -R
,然后运行
I've noticed that if I give full permissions on my machine to the data directory sudo chmod 777 ./data/solr/ -R
and I run the Docker again, everything is fine.
我想问题出在 solr
用户不是我的机器时,问题就来了,因为Docker创建了 root:root 的code> data / solr 文件夹。我的 ./ data
文件夹被忽略,我无法管理这些文件夹权限。
I guess the issue comes when the solr
user is not my machine, because Docker creates the data/solr
folder with root:root
. Having my ./data
folder gitignored, I cannot manage these folder permissions.
我想知道一种管理权限的解决方法正确地以持久化数据为目的
I'd like to know a workaround to manage permissions properly with the purpose of persisting data
推荐答案
这是已知的问题;使用docker-compose:Docker引擎创建的所有文件都归root:root拥有。通常,它可以通过以下两种方式之一解决:
It's a known "issue" with docker-compose: all files created by Docker engine are owned by root:root. Usually it's solved in one of the two ways:
- 提前创建音量。对于您的情况,可以预先创建具有适当权限的./data/solr目录。您可以使任何人都可以访问它,或者更好的是,将其所有者更改为
solr
用户。solr
用户和组ID硬编码在solr图像内:8983()
- Create the volume in advance. In your case, you can create the ./data/solr directory in advance, with appropriate permissions. You might make it accessible to anyone, or, better, change its owner to the
solr
user. Thesolr
user and group ids are hardcoded inside the solr image: 8983 (Dockerfile.template)
mkdir -p ./data/solr
sudo chown 8983:8983 ./data/solr
- 如果要避免在docker-compose之前运行其他命令,可以创建其他容器来修复权限:
version: "3"
services:
initializer:
image: alpine
container_name: solr-initializer
restart: "no"
entrypoint: |
/bin/sh -c "chown 8983:8983 /solr"
volumes:
- ./data/solr:/solr
solr:
depends_on:
- initializer
image: solr:8.6.2
container_name: myproject-solr
ports:
- "8983:8983"
volumes:
- ./data/solr:/var/solr/data
networks:
static-network:
ipv4_address: 172.20.1.42
这篇关于Docker持久卷没有权限(Apache Solr)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!