本文介绍了Docker卷访问错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个Docker文件,用于在Windows Server 2016上使用Docker来构建Elasticsearch的图像。创建一个图像是完美的,我可以使用 docker run --rm -p 9200:9200< ;图像标识> 。我可以使用容器的ip地址成功访问Elasticsearch。链接到。

I have created a Dockerfile to build an image for Elasticsearch using Docker on Windows Server 2016. Creating an image works perfectly, and I can run it using docker run --rm -p 9200:9200 <imageid>. I can successfully access Elasticsearch using the ip address of the container. Link to Github Project.

弹性搜索.yml文件配置日志和数据路径:

The elasticsearch.yml file configures the log and data path:

cluster.name: docker-cluster
network.host: 0.0.0.0

path.logs: C:/persistent/logs/
path.data: C:/persistent/data/

discovery.zen.minimum_master_nodes: 1

当我尝试使用卷来持久保存日志和数据时遇到麻烦主办。我用命令创建了一个卷

I run into trouble when I try to use a volume to persist the logs and the data on the host. I created a volume with the command

docker volume create elasticsearch

并运行容器:

docker run --rm -p 9200:9200 -v elasticsearch:C:\persistent <imageid>

哪个给我一个java异常:

Which gives me a java exception:

[2017-05-10T09:00:47,568][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: Unable to access 'path.logs' (C:\persistent\logs)
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:127) ~[elasticsearch-5.4.0.jar:5.4.0]
        <snip>
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.4.0.jar:5.4.0]
Caused by: java.lang.IllegalStateException: Unable to access 'path.logs' (C:\persistent\logs)
        at org.elasticsearch.bootstrap.Security.addPath(Security.java:413) ~[elasticsearch-5.4.0.jar:5.4.0]
        <snip>
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.4.0.jar:5.4.0]
        ... 6 more
Caused by: java.nio.file.NoSuchFileException: C:\persistent\logs
        at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79) ~[?:1.8.0_131]
        <snip>
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.4.0.jar:5.4.0]
        ... 6 more

奇怪的是,日志文件是在卷中创建的,并包含异常详细信息。因此日志文件夹中的日志文件表示日志文件夹无法访问。

The strange thing is that the log files are created in the volume and include the exception detail. So the log file in the logs folder says the logs folder can't be accessed.

我尝试在主机上创建日志和数据文件夹,并让弹性搜索创建它们。我尝试使用两个不同的卷,一个用于日志,一个用于数据。它们都导致相同的错误。

I have tried creating the logs and data folder on the host and letting Elasticsearch create them. I've tried using two different volumes, one for logs and one for data. They all result in the same error.

我需要做些什么才能使Elasticsearch正确访问日志和数据文件夹?

What do I need to do to make it so the logs and data folder are properly accessible to Elasticsearch?

推荐答案

最后找到答案。或至少是解决方法。 Java Path.toRealPath()方法不能正确地翻译卷路径的符号链接。解决方法是将容器内的卷文件夹映射到驱动器盘符,并使用映射的驱动器访问它.JB

Finally found the answer here. Or at least the workaround. The Java Path.toRealPath() method doesn't translate the symlink of the volumes path properly. The workaround is to "map" the volume folder inside the container to a drive letter, and have the java program access it using the mapped drive.

VOLUME c:/data
RUN powershell Set-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices' -Name 'G:' -Value '\??\C:\data' -Type String

这篇关于Docker卷访问错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 19:53