gpt4 book ai didi

docker - 运行容器时权限被拒绝(docker 1.12.5)

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

我试图在安装了Docker 1.12.5的新创建的VM上运行ElasticSearch容器,但遇到了Permission Denied异常。让我感到困惑的是,在我的旧版VM(使用Docker 1.12.2)中,一切运行正常。我想念什么?

异​​常:

Exception in thread "main" SettingsException[Failed to open stream for url [/usr/share/elasticsearch/config/elasticsearch.yml]]; nested: AccessDeniedException[/usr/share/elasticsearch/config/elasticsearch.yml];
Likely root cause: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/config/elasticsearch.yml
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
at java.nio.file.Files.newByteChannel(Files.java:361)
at java.nio.file.Files.newByteChannel(Files.java:407)
at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
at java.nio.file.Files.newInputStream(Files.java:152)
at org.elasticsearch.common.settings.Settings$Builder.loadFromPath(Settings.java:1067)
at org.elasticsearch.node.internal.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:88)
at org.elasticsearch.common.cli.CliTool.<init>(CliTool.java:107)
at org.elasticsearch.common.cli.CliTool.<init>(CliTool.java:100)
at org.elasticsearch.bootstrap.BootstrapCLIParser.<init>(BootstrapCLIParser.java:48)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:242)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)

系统:
  • Windows 10,安装了VirtualBox,
  • XUbuntu 16.04镜像,带有包含Dockerfile和elasticsearch.yml配置文件的共享主机文件夹。

  • Docker文件:
    FROM openjdk:8-jre

    ENV VERSION 2.4.1

    RUN groupadd -r elasticsearch && useradd -r -g elasticsearch elasticsearch
    RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 46095ACC8548582C1A2699A9D27D666CD88E42B4
    RUN set -x \
    && apt-get update && apt-get install -y --no-install-recommends apt-transport-https && rm -rf /var/lib/apt/lists/* \
    && echo 'deb http://packages.elasticsearch.org/elasticsearch/2.x/debian stable main' > /etc/apt/sources.list.d/elasticsearch.list
    RUN set -x \
    && apt-get update \
    && apt-get install -y --no-install-recommends elasticsearch=$VERSION \
    && rm -rf /var/lib/apt/lists/*

    ENV PATH /usr/share/elasticsearch/bin:$PATH

    WORKDIR /usr/share/elasticsearch
    RUN set -ex \
    && for path in \
    ./data \
    ./logs \
    ./config \
    ./config/scripts \
    ; do \
    mkdir -p "$path"; \
    chown -R elasticsearch:elasticsearch "$path"; \
    done

    COPY config ./config
    VOLUME /usr/share/elasticsearch/data
    VOLUME /usr/share/elasticsearch/logs

    EXPOSE 9200 9300
    USER elasticsearch
    CMD elasticsearch

    除了Dockerfile以外,还保留 以下文件结构:
    - config
    - elasticsearch.yml

    由于该镜像可在其他VM上运行,因此我认为其配置应该正确。我也不认为问题出在ElasticSearch上,因为我似乎有另一张图片也遇到了同样的问题(H2)。我是Docker和Linux的初学者。

    最佳答案

    在以下位置复制配置后,设置文件权限:

    COPY config ./config
    RUN chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/config

    您还可以作为根用户创建 chown目录并对其进行 /usr/share/elasticsearch,然后完成将 /usr/share/elasticsearch的内容作为 USER elasticsearch处理的其余步骤

    关于docker - 运行容器时权限被拒绝(docker 1.12.5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41366140/

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