gpt4 book ai didi

elasticsearch - travis上的Elasticsearch Docker失败,文件夹访问被拒绝

转载 作者:行者123 更新时间:2023-12-02 23:17:42 24 4
gpt4 key购买 nike

我在travis上使用Elasticsearch docker镜像时遇到问题。

给定这个docker-compose.yml文件:

version: '2'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2
ports:
- "9200:9200"
environment:
- "discovery.type=single-node"
- "transport.host=127.0.0.1"
- "xpack.security.enabled=false"
volumes:
- ./elasticsearch/data:/usr/share/elasticsearch/data
kibana:
image: docker.elastic.co/kibana/kibana:6.4.2
ports:
- "5601:5601"
depends_on:
- elasticsearch
environment:
- "ELASTICSEARCH_URL: http://elasticsearch:9200"

和以下 .travis.yml文件:
before_install:
- docker-compose up -d
- docker-compose logs -f &
- wget -q --waitretry=1 --retry-connrefused -T 10 -O - http://127.0.0.1:9200
[...more stuff here...]

Elasticsearch引擎无法启动,但出现以下异常:
elasticsearch_1  | [2018-10-19T08:09:23,574][INFO ][o.e.n.Node               ] [] initializing ...
elasticsearch_1 | [2018-10-19T08:09:23,627][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
elasticsearch_1 | org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: Failed to create node environment
elasticsearch_1 | at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | Caused by: java.lang.IllegalStateException: Failed to create node environment
elasticsearch_1 | at org.elasticsearch.node.Node.<init>(Node.java:277) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.node.Node.<init>(Node.java:256) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:213) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | ... 6 more
elasticsearch_1 | Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes
elasticsearch_1 | at sun.nio.fs.UnixException.translateToIOException(UnixException.java:90) ~[?:?]
elasticsearch_1 | at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[?:?]
elasticsearch_1 | at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) ~[?:?]
elasticsearch_1 | at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:385) ~[?:?]
elasticsearch_1 | at java.nio.file.Files.createDirectory(Files.java:682) ~[?:?]
elasticsearch_1 | at java.nio.file.Files.createAndCheckIsDirectory(Files.java:789) ~[?:?]
elasticsearch_1 | at java.nio.file.Files.createDirectories(Files.java:775) ~[?:?]
elasticsearch_1 | at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:203) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.node.Node.<init>(Node.java:274) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.node.Node.<init>(Node.java:256) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:213) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.4.2.jar:6.4.2]
elasticsearch_1 | ... 6 more

注意上面的 Caused by: java.nio.file.AccessDeniedException。文件夹 ./elasticsearch/data存在,并且像往常一样归属于 travis:travis

我需要在这里找到根本原因的帮助,并找到一种解决方案,希望该解决方案不涉及使用 chownchmod强制强行使用权限,并且也可以在我的本地计算机上使用(即没有硬编码的uid)。

最佳答案

默认情况下,Docker容器始终以root用户身份运行。结果,所有正在运行的进程,共享卷,文件夹,文件将由root用户拥有。

如果您不手动创建共享文件夹,则docker将创建它,并将由root用户拥有:

$ ls -la
total 16
drwxrwxr-x 3 ubuntu ubuntu 4096 Oct 19 23:02 .
drwxrwxr-x 14 ubuntu ubuntu 4096 Oct 19 21:57 ..
-rw-rw-r-- 1 ubuntu ubuntu 534 Oct 19 21:58 docker-compose.yaml
drwxr-xr-x 3 root root 4096 Oct 19 23:02 elasticsearch

$ ls -laR elasticsearch
elasticsearch:
total 12
drwxr-xr-x 3 root root 4096 Oct 19 23:02 .
drwxrwxr-x 3 ubuntu ubuntu 4096 Oct 19 23:02 ..
drwxr-xr-x 2 root root 4096 Oct 19 23:02 data

elasticsearch/data:
total 8
drwxr-xr-x 2 root root 4096 Oct 19 23:02 .
drwxr-xr-x 3 root root 4096 Oct 19 23:02 ..

这就是为什么有 java.nio.file.AccessDeniedException的原因。

如果我们在用户启动容器之前(在 ./elasticsearch/data命令之前)创建启动docker容器的用户的权限,创建 docker-compose up文件夹,则可以避免。对于您的特殊情况是:
before_install:
- mkdir -p elasticsearch/data
- docker-compose up -d
- docker-compose logs -f &
- wget -q --waitretry=1 --retry-connrefused -T 10 -O - http://127.0.0.1:9200
[...more stuff here...]

关于elasticsearch - travis上的Elasticsearch Docker失败,文件夹访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52897605/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com